set_exception_handler() - 语法
string set_exception_handler ( callback $exception_handler );
如果在try/catch块中没有捕获到异常,则此函数设置默认的异常处理程序。调用EXCEPTION_HANDLER后,执行将停止。
EXCEPTION_HANDLER - 发生未捕获异常时要调用的函数的名称。必须在调用SET_EXCEPTION_HANDLER()之前定义此函数。
set_exception_handler() - 返回值
它返回先前定义的异常处理程序的名称,如果出错,则返回NULL。如果以前没有定义处理程序,也会返回NULL。
set_exception_handler() - 示例
<?php function exception_handler($exception) { echo "Uncaught exception is : " , $exception->getMessage(), "\n"; } set_exception_handler('exception_handler'); set_exception_handler(); throw new Exception('Not Found Exception'); echo "not included Executed\n"; ?>
这将产生以下输出-
Uncaught exception is: Not Found Exception
参考链接
https://www.learnfk.com/php/php-function-set-exception-handler.html