Usage of set_exception_handler function in ThinkPHP, thinkphpc function
The example in this article describes the usage of the set_exception_handler function in ThinkPHP. Share it with everyone for your reference. The specific method is as follows:
Function:
Copy code The code is as follows:
string set_exception_handler (callback $exception_handler)
Definition and usage:
The set_exception_handler() function sets a user-defined exception handling function.
This function is used to create the user's own exception handling method during runtime.
This function returns the old exception handler, or null on failure.
Syntax:
set_exception_handler(exception_function)
Parameters |
Description |
error_function |
参数 |
描述 |
error_function |
必需。规定未捕获的异常发生时调用的函数。
该函数必须在调用 set_exception_handler() 函数之前定义。
这个异常处理函数需要需要一个参数,即抛出的 exception 对象。
|
Required. Specifies the function to be called when an uncaught exception occurs.
This function must be defined before calling the set_exception_handler() function.
This exception handling function requires one parameter, which is the thrown exception object.
|
Tips and Notes:
Tip
: After this exception handler is called, the script will stop executing.
I also discovered this function when I was looking at the TP code, and I couldn’t figure it out. Why didn’t I care about these things before? (beating chest and stamping feet...)
Let’s continue to look at how TP is implemented. Well, why must we use TP? Okay, I'll bring over the examples from the manual in a moment.
Copy code
The code is as follows:
public function appException($e)
{
Halt($e->__toString());
}
set_exception_handler(array(&$this,"appException"));
Haha, this is simple, right? Because I have not given the implementation of the halt method, this is enough.
Look at the example in the manual again,
Copy code
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 just sets which custom function to call when your program needs to throw an exception.
It’s that simple
Note:
How to use PHP functions in thinkphp template
ThinkPHP framework template uses system functions
// Two methods can be used // 1. Directly use the tag// 2. Use template tag {$vo.name|mb_strlen=0,20}
http://www.bkjia.com/PHPjc/904013.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904013.html
TechArticle