restore_exception_handler ()函数恢复PHP自身的异常处理。会清除set_exception_handler中用户自定义的函数处理方式
例子:
function handleException(Exception $e) { do{ echo "<b>错误信息</b>:" . $e->getMessage() . "</br>"; echo "<b>错误码</b>:" . $e->getCode() . "</br>"; echo "<b>错误文件</b>:" . $e->getFile() . "</br>"; echo "<b>错误行数</b>:" . $e->getLine() . "</br>"; echo "<b>错误行数</b>:" . $e->getPrevious() . "</br>"; echo "<b>异常追踪信息</b>:</br>"; echo "</pre>" . print_r($e->getTrace(), true) . "</pre></br>"; echo "***********</br>"; } while($e = $e->getPrevious()); } set_exception_handler("handleException"); function test($name) { throw new Exception("Test exception", 1000); } restore_exception_handler(); test("codyi");
结果:
Fatal error: Uncaught exception 'Exception' with message 'Test exception' in /Users/liguosong/work/php/Testing/test.php on line 21 Exception: Test exception in /Users/liguosong/work/php/Testing/test.php on line 21 Call Stack: 0.0002 251616 1. {main}() /Users/liguosong/work/php/Testing/test.php:0 0.0003 252240 2. test(???) /Users/liguosong/work/php/Testing/test.php:25