-
-
Save kkreft/5d3866434463067dd4a1df385a4d5590 to your computer and use it in GitHub Desktop.
Custom error handler for stack trace Medium article
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 | |
set_exception_handler( function(\Exception $e) { | |
$rows = "\n ========= \n"; | |
$exception = sprintf( | |
"Exception: %s \n Origin: %s on line %s \n", | |
$e->getMessage(), | |
$e->getFile(), | |
$e->getLine() | |
); | |
$trace = (array) $e->getTrace(); | |
arsort($trace); | |
foreach($trace as $key=>$item) { | |
$rows .= sprintf("%s %s [%s] \n", $item['file'], $item['function'], $item['line']); | |
} | |
echo $exception . $rows; | |
die; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment