Skip to content

Instantly share code, notes, and snippets.

@rockoo
Last active May 24, 2022 12:31
Show Gist options
  • Save rockoo/7f3bf18af89b0701c7468bb323d59548 to your computer and use it in GitHub Desktop.
Save rockoo/7f3bf18af89b0701c7468bb323d59548 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