为什么不试试......赶上?
$has_errors = false;
try {
// code here
} catch (exception $e) {
// handle exception, or save it for later
$has_errors = true;
}
if ($has_errors!==false)
print 'This did not work';编辑:
以下是set_error_handler的示例,它将处理在try ... catch块的上下文之外发生的任何错误。如果PHP配置为显示通知,这也将处理通知。
基于以下代码:http://php.net/manual/en/function.set-error-handler.php
set_error_handler('genericErrorHandler');
function genericErrorHandler($errno, $errstr, $errfile, $errline) {
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting
return;
}
switch ($errno) {
case E_USER_ERROR:
echo "My ERROR [$errno] $errstr
\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")
\n";
echo "Aborting...
\n";
exit(1);
break;
case E_USER_WARNING:
echo "My WARNING [$errno] $errstr
\n";
break;
case E_USER_NOTICE:
echo "My NOTICE [$errno] $errstr
\n";
break;
default:
echo "Unknown error type: [$errno] $errstr
\n";
break;
}
/* Don't execute PHP internal error handler */
return true;
}
$v = 10 / 0 ;
die('here');