PHP set_exception_handler () function
Definition and Usage
set_exception_handler () function to set the exception handler user-defined.
This function is used to create a user during run their own exception handling.
This function returns the old exception handler if it fails to return NULL.
grammar
set_exception_handler(exception_function)
参数 | 描述 |
---|---|
exception_function | 必需。规定未捕获的异常发生时调用的函数。 该函数必须在调用 set_exception_handler() 函数之前定义。这个异常处理函数需要需要一个参数,即抛出的 exception 对象。 |
Tips and Notes
Tip: After the exception handler is invoked, the script will stop executing.
Examples
<?php
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}
set_exception_handler('myException');
throw new Exception('Uncaught Exception occurred');
?>
function myException($exception)
{
echo "<b>Exception:</b> " , $exception->getMessage();
}
set_exception_handler('myException');
throw new Exception('Uncaught Exception occurred');
?>
The output of the code above is as follows:
Exception:Uncaught Exception occurred
Complete PHP Error Reference