Set_exception_handler function usage in ThinkPHP, thinkphpc function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Set_exception_handler function usage in ThinkPHP, thinkphpc function. The set_exception_handler function is used in ThinkPHP. the thinkphpc function describes the usage of set_exception_handler in ThinkPHP. Share it with you for your reference. Specific set_exception_handler function usage in ThinkPHP, thinkphpc function

This example describes how to use the set_exception_handler function in ThinkPHP. Share it with you for your reference. The specific method is as follows:

Function:

The code is as follows:

String set_exception_handler (callback $ exception_handler)


Definition and usage:
The set_exception_handler () function sets the custom exception handling function.
This function is used to create your own exception handling methods during runtime.
This function returns the old exception handler. if it fails, null is returned.

Syntax:
Set_exception_handler (exception_function)

Parameters Description
Error_function

Required. Specifies the function called when an uncaptured exception occurs.

This function must be defined before the set_exception_handler () function is called.

This exception handling function requires a parameter, that is, the thrown exception object.

Tips and notes:

Prompt: After the exception handler is called, the script stops running.

I also find this function when I look at the TP code, so I can't understand it. why have I never cared about these things before? (Beat your chest at ing ...)
Let's take a look at how TP is implemented. er, why must we use TP. Well, I will move the manual examples later.

The code is as follows:

Public function appException ($ e)
{
Halt ($ e->__ toString ());
}
Set_exception_handler (array (& $ this, "appException "));


Oh, is this simple? Because I didn't provide the implementation of the halt method, this is enough.
Let's look at the example in the manual,

The code is as follows:

Function exception_handler ($ exception ){
Echo "Uncaught exception:", $ exception-> getMessage (), "n ";
}
Set_exception_handler ('exception _ handler ');
Throw new Exception ('uncaught exception ');
Echo "Not Executedn ";


In fact, set_exception_handler sets the custom function to be called when your program needs to throw an exception.
That's simple.

Note:
Set_exception_handler ("myException") not only accepts functions, but also accepts class methods (public static methods and public non-static methods are acceptable), but must be transmitted in arrays, the first value of the array is "class name", and the second parameter is "method name"

I hope this article will help you with ThinkPHP framework programming.


How to use PHP functions for thinkphp templates

That's what I wrote. Yes. {$ Create_time | date = 'Y-m-d H: I: S', ###}, but $ create_time should be an 11-digit number.
Reference: doc.thinkphp1.cn/manual/use_function.html

The ThinkPHP framework template uses system functions.

// Two methods can be used // 1. Tag // 2. use the template tag {$ Vo. name} {$ Vo. name | mb_strlen = 0, 20}

In this example, the set_exception_handler function is used in ThinkPHP. Share it with you for your reference. Details...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.