Created
February 23, 2010 02:08
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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