<u></u>set_error_handler
用来捕捉trigger_error
,
<u></u>set_exception_handler
用来捕捉throw new Exception
例如:
set_error_handler("testErrorHandler");
function testErrorHandler($errorNumber,$errorMessage,$errorFile,$errorLine){
echo "Error Number: ".$errorNumber."<br/>";
echo "Error Message: ".$errorMessage."<br/>";
echo "Error File: ".$errorFile."<br/>";
echo "Error Line: ".$errorLine."<br/>";
die();
}
set_exception_handler("testExceptionHandler");
function testExceptionHandler($exception){
echo "Exception Code: ".$exception->getCode()."<br/>";
echo "Exception Message: ".$exception->getMessage()."<br/>";
echo "Exception File: ".$exception->getFile()."<br/>";
echo "Exception Line: ".$exception->getLine()."<br/>";
die();
}
throw new Exception("A custom exception has been thrown.");
trigger_error("A custom error has been triggered.");