Skip to content

Instantly share code, notes, and snippets.

@xuecan
Created May 30, 2016 13:46
Show Gist options
  • Select an option

  • Save xuecan/b5465208e4e50a8ad7ee28744f2f4394 to your computer and use it in GitHub Desktop.

Select an option

Save xuecan/b5465208e4e50a8ad7ee28744f2f4394 to your computer and use it in GitHub Desktop.
PHP 5 ErrorException Handler
/**
* 错误处理器
*
* 将 `E_USER_ERROR`、 `E_WARNING`、 `E_USER_WARNING` 和 `E_RECOVERABLE_ERROR`
* 错误转成 `\ErrorException` 异常抛出。其它类型的错误信息保留使用默认的错误处理机制。
*
* @throws \ErrorException 对于需要转换的错误,抛出异常
* @return bool 对于无需转换的错误,总是返回 false
*/
function handleErrorException($errno, $errstr, $errfile = __FILE__, $errline = __LINE__)
{
switch ($errno) {
case E_USER_ERROR:
case E_WARNING:
case E_USER_WARNING:
case @E_RECOVERABLE_ERROR:
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
break;
default:
return false;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment