I build some api endpoint, and trying to work on logging exception, so I purposely remove database and run the endpoint to get PDOException.
My question is, if I did not caught the exception, when I ran the endpoint through postman, it shows me a much more detailed message, stack trace, etc (about 1000 lines),
but if I caught the exception with try catch block something like this
catch (\Exception $exception) {
print_r($exception->__toString());
print_r("\n\n");
die;
}
It is so much less details. Why is that? and is there anyway to print the same exact data that we got when we don't caught the exception?
$exceptionobject holds a lot more information than is rendered by the magic __toString() method, just take a look at the actual object methods and properties like getTrace()debug_backtrace(). As for the reason why, is that Xdebug is probably enabled, which is a PHP extension that will loop through the results of that function to give you a stack trace.__toString()explicitly; the whole point of the magic method is that it's called implicitly (magically) if you try to echo the object