自定义异常set_exception_handler(6)

set_exception_handler() 函数设置用户自定义的异常处理函数。
该函数用于创建运行时期间的用户自己的异常处理方法。
用在没有用try/catch块来捕获的异常,也就是说不管你抛出的异常有没有人捕获,如果没有人捕获就会进入到该方法中,并且在回调函数调用后异常会中止
set_exception_handler ( callable$exception_handler ) : callable

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";

你可能感兴趣的:(自定义异常set_exception_handler(6))