I have a PHP function which I call when I caught an exception. It accepts that exception as optional parameter, so it can show it for debugging purposes:
public static function notFound($resource, \Exception $exception = null) {
// [... normal error handling ...]
if (DEBUG && $exception != null) {
echo '<br><br><h2>Stacktrace:</h2>';
print_r($exception);
}
die();
}
What I would like is to display this exception the same way uncaught exceptions and warnings are displayed with xdebug (styled with CSS and HTML, possibly with a different color scheme). Like this (created by echo $exception->getTrace();
):
If I use print_r($exception);
I get this, which seems to contain at least some of the needed output for xdebug:
I have tried echo $exception->xdebug_message;
, var_dump($exception);
, and var_dump($exception->xdebug_message);
, but none of it worked. The last one seems to be the closed to what I want, but I can't get it to work correctly:
Is there a way to use xdebug styling for caught exceptions?
Answered here: https://stackoverflow.com/a/24768176/1286814.
In short, you just need to wrap xdebug_message
inside a table:
echo '<table>'.$e->xdebug_message.'</table>';
Ok, I found a solution in this list of all xdebug functions:
xdebug_print_function_stack($exception);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With