PHP 中的 restore_exception_handler() 函数
phpprogrammingserver side programming更新于 2025/8/29 21:52:17
restore_exception_handler() 函数用于恢复之前的异常处理程序。在使用 set_exception_handler() 更改异常处理程序函数后,可以使用该函数恢复到之前的异常处理程序(可以是内置函数或用户定义函数)。
语法
restore_exception_handler()
参数
- 不适用
返回值
restore_exception_handler() 函数始终返回 TRUE。
示例
下面是一个例子 −
<?php
function customException1($exception) {
echo "[" . __FUNCTION__ . "]" . $exception->getMessage();
}
function customException2($exception) {
echo "[" . __FUNCTION__ . "]" . $exception->getMessage();
}
function customException3($exception) {
echo "[" . __FUNCTION__ . "]" . $exception->getMessage();
}
set_exception_handler("customException1");
set_exception_handler("customException2");
set_exception_handler("customException3");
restore_exception_handler();
// throwing exception
throw new Exception("Triggers the first exception handler!");
?>
输出
以下是输出 −
[customException1] Triggers the first exception handler!

