array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.set-exception-handler.php', 1 => 'set_exception_handler', ), 'up' => array ( 0 => 'ref.errorfunc.php', 1 => '错误处理 函数', ), 'prev' => array ( 0 => 'function.set-error-handler.php', 1 => 'set_error_handler', ), 'next' => array ( 0 => 'function.trigger-error.php', 1 => 'trigger_error', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/errorfunc/functions/set-exception-handler.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
set_exception_handler — 设置用户自定义的异常处理函数
设置默认的异常处理程序,用于没有用 try/catch 块来捕获的异常。
在 callback
调用后异常会中止。
示例 #1 set_exception_handler() 范例
<?php
function exception_handler(Throwable $exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
throw new Exception('Uncaught Exception');
echo "Not Executed\n";
?>