php,有没有办法将所有通知/警告变成例外? [英] Php, is there a way to turn all notices/warnings into an exception?

查看:60
本文介绍了php,有没有办法将所有通知/警告变成例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了错误处理程序:

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.

推荐答案

是. 这正是创建ErrorException的原因.参见 http://php.net/manual/en/class.errorexception.php

Yes. this is exactly why the ErrorException was created. see 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");

这篇关于php,有没有办法将所有通知/警告变成例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆