Log caught exception with stack trace

error_log($e);

does what you want. It logs exactly the same thing that would have been logged if you didn’t catch the exception, minus the word ‘Uncaught’ at the beginning. It does this because that’s what the Exception class’s __toString() magic method returns.

You can do this in a catch block:

try {
    foo();
} catch (Exception $e) {
    error_log("Caught $e");
}

Or in the exception handler:

set_exception_handler(function($exception) {
    error_log($exception);
    error_page("Something went wrong!");
});

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)