Home > Backend Development > PHP Tutorial > How to use set_exception_handler function in ThinkPHP, thinkphpc function_PHP tutorial

How to use set_exception_handler function in ThinkPHP, thinkphpc function_PHP tutorial

WBOY
Release: 2016-07-13 10:15:36
Original
1084 people have browsed it

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:
set_exception_handler("myException") can not only accept functions, but also class methods (both public static methods and public non-static methods are acceptable), but it needs to be passed in the form of an array. The first value of the array is "class name", the second parameter is "method name"

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

How to use PHP functions in thinkphp template



That’s what it says. Yes. {$create_time|date='Y-m-d H:i:s',###}, but $create_time should be an 11-digit number

Reference: doc.thinkphp.cn/manual/use_function.html

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
Usage of set_exception_handler function in ThinkPHP, thinkphpc function This article describes the usage of set_exception_handler function in ThinkPHP. Share it with everyone for your reference. Specifically...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template