restore_exception_handler
(PHP 5, PHP 7, PHP 8)
restore_exception_handler — 恢復之前定義過的異常處理函式。
說明
restore_exception_handler(): bool
在使用 set_exception_handler() 改變異常處理函式之後,此函式可以 用於還原之前的異常處理程式(可以是內建的或者也可以是使用者所定義的函式)。
返回值
該函式總是返回 true
。
範例
示例 #1 restore_exception_handler() 範例
<?php
function exception_handler_1(Exception $e)
{
echo '[' . __FUNCTION__ . '] ' . $e->getMessage();
}
function exception_handler_2(Exception $e)
{
echo '[' . __FUNCTION__ . '] ' . $e->getMessage();
}
set_exception_handler('exception_handler_1');
set_exception_handler('exception_handler_2');
restore_exception_handler();
throw new Exception('This triggers the first exception handler...');
?>
以上例程會輸出:
[exception_handler_1] This triggers the first exception handler...
參見
- set_exception_handler() - 設定使用者自定義的異常處理函式
- set_error_handler() - 設定使用者自定義的錯誤處理函式
- restore_error_handler() - 還原之前的錯誤處理函式
- error_reporting() - 設定應該報告何種 PHP 錯誤