[英]Php, is there a way to turn all notices/warnings into an exception?
I already set my error handler: 我已经设置了错误处理程序:
set_error_handler (function($errno, $errstr, $errfile, $errline, array $errcontext) {
$s = date('Ymd_His');
switch ($errno)
{
case E_USER_ERROR:
$s.= '_E_';
break;
case E_USER_WARNING:
$s.= '_W_';
break;
case E_USER_NOTICE:
$s.= '_N_';
break;
default:
$s.= '_U_';
break;
}
file_put_contents (APP_PATH_CACHE.'/log'.$s.'_'.rand(1,99999).'.html', print_r(get_defined_vars(), true));
}, E_ALL);
but can it be turn into an exception? 但它可以变成例外吗? So that I could see the flow.
这样我才能看到流动。
Yes. 是。 this is exactly why the ErrorException was created.
这正是ErrorException创建的原因。 see http://php.net/manual/en/class.errorexception.php
见http://php.net/manual/en/class.errorexception.php
function exception_error_handler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
// This error code is not included in error_reporting
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
}
set_error_handler("exception_error_handler");
Yes it can be simply done. 是的,它可以简单地完成。 Best way is to create your own class that extends from \\Exception and in your error_handler() throw object of this new class.
最好的方法是创建自己的类,该类从\\ Exception和此新类的error_handler()throw对象中扩展。
You can do it also in simple way after 您也可以在以后以简单的方式完成
file_put_contents (APP_PATH_CACHE.'/log'.$s.'_'.rand(1,99999).'.html', print_r(get_defined_vars(), true));
add 加
throw new Exception($errst, $errno);
where first param is message and second is error number 其中第一个参数是消息,第二个是错误号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.