Skip to content

Instantly share code, notes, and snippets.

@kkreft
Forked from rockoo/custom-handler.php
Created May 24, 2022 12:31
Show Gist options
  • Save kkreft/5d3866434463067dd4a1df385a4d5590 to your computer and use it in GitHub Desktop.
Save kkreft/5d3866434463067dd4a1df385a4d5590 to your computer and use it in GitHub Desktop.
Custom error handler for stack trace Medium article
<?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