Last active
December 30, 2015 12:29
-
-
Save evaisse/7829138 to your computer and use it in GitHub Desktop.
This file contains 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 my_exception_handler($exception) | |
{ | |
print '<pre>'; | |
print $exception; | |
print '</pre>'; | |
} | |
set_exception_handler("my_exception_handler"); | |
/** | |
* Handling fatal error | |
* | |
* @return void | |
*/ | |
function my_error_handler($errno, $errstr, $errfile, $errline, $errcontext) | |
{ | |
$exception = new ErrorException($errstr, $errno, 0, $errfile, $errline); | |
if ($errno === E_RECOVERABLE_ERROR | |
&& strpos($errstr, " must be an ") !== false | |
) { | |
throw $exception; | |
} | |
if (!(bool)($errno & error_reporting())) { | |
return false; // error has been silenced by @ operator | |
} | |
if ($errno === E_NOTICE || $errno === E_USER_NOTICE || $errno === E_WARNING || $errno === E_STRICT) { | |
return; | |
} | |
throw $exception; | |
} | |
set_error_handler('my_error_handler'); | |
/** | |
* Handling fatal error | |
* | |
* @return void | |
*/ | |
function my_fatal_error_handler() | |
{ | |
$e = error_get_last(); | |
/** | |
* Every "bad" error is logged | |
*/ | |
if (is_array($e) && isset($e['type']) && ($e['type'] & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_PARSE))) { | |
if (!class_exists("FatalErrorException")) { | |
class FatalErrorException extends ErrorException {} | |
} | |
throw new ErrorException($e['message'], $e['type'], 0, $e['file'], $e['line']); | |
} | |
} | |
register_shutdown_function('my_fatal_error_handler'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment