restore_exception_handler

(PHP 5, PHP 7, PHP 8)

restore_exception_handler 恢復(fù)之前定義過的異常處理函數(shù)。

說明

restore_exception_handler(): bool

在使用 set_exception_handler() 改變異常處理函數(shù)之后,此函數(shù)可以 用于還原之前的異常處理程序(可以是內(nèi)置的或者也可以是用戶所定義的函數(shù))。

返回值

該函數(shù)總是返回 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...

參見