restore_exception_handler
恢复之前定义过的异常处理函数
PHP 5.0.0及更高版本
restore_exception_handler() 函数用于恢复先前设置的异常处理器。在 PHP 中,异常处理器可以通过 set_exception_handler() 设置,而 restore_exception_handler() 则用于恢复到默认的异常处理器。
void restore_exception_handler(void)
本函数没有参数。
本函数没有返回值。
<?php
// 自定义异常处理器
function custom_exception_handler($exception) {
echo "异常信息: " . $exception->getMessage();
}
<p>// 设置自定义异常处理器<br>
set_exception_handler('custom_exception_handler');</p>
<p>// 引发异常<br>
throw new Exception("自定义异常发生了!");</p>
<p>// 恢复默认异常处理器<br>
restore_exception_handler();</p>
<p>// 这时,默认的异常处理器会处理异常<br>
throw new Exception("默认异常处理器执行。");<br>
?><br>
1. 首先定义了一个自定义的异常处理器 custom_exception_handler,输出异常信息。
2. 使用 set_exception_handler() 设置了该自定义异常处理器。
3. 然后通过 throw 语句引发一个异常,触发 custom_exception_handler 处理该异常。
4. 接下来调用 restore_exception_handler() 恢复默认的异常处理器。
5. 再次引发一个异常时,将由 PHP 的默认异常处理器来处理。