Skip to content

Instantly share code, notes, and snippets.

@gabetax
Created February 23, 2010 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabetax/311766 to your computer and use it in GitHub Desktop.
Save gabetax/311766 to your computer and use it in GitHub Desktop.
PHP error handler. Converts all errors to logged exceptions. Warnings are displayed, errors are thrown.
<?php
function ChitinErrorHandler ($errno, $errstr, $errfile, $errline, $errcontext) {
$e = new ErrorException($errstr, 0, $errno, $errfile, $errline);
error_log($e);
switch ($errno) {
case E_STRICT:
// Fuck E_STRICT. Seriously.
break;
case E_NOTICE:
case E_WARNING:
case E_USER_NOTICE:
case E_USER_WARNING:
// Don't even
if ($_ENV['SERVER_ENV'] == 'production')
break;
// These are unworthy of throwing an exception - just send the alert
if (ini_get('error_reporting') & $errno)
echo "<pre class=\"error\">$e</pre>\n";
break;
default:
throw $e;
}
}
set_error_handler('ChitinErrorHandler', error_reporting());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment