1 bootstrap.inc _backdrop_exception_handler($exception)

Provides custom PHP exception handling.

Uncaught exceptions are those not enclosed in a try/catch block. They are always fatal: the execution of the script will stop as soon as the exception handler exits.


$exception: The exception object that was thrown.


core/includes/bootstrap.inc, line 2959
Functions that need to be loaded on every Backdrop request.


function _backdrop_exception_handler($exception) {
  require_once BACKDROP_ROOT . '/core/includes/errors.inc';

  try {
    // Log the message to the watchdog and return an error page to the user.
    _backdrop_log_error(_backdrop_decode_exception($exception), TRUE);
  catch (Exception $exception2) {
    // Default the status code to 500 before any other code is run. This will
    // make any FATAL errors return 500 responses instead of 200, and also
    // account for cases where an exception was thrown before the 500 status
    // could be set (e.g. while loading a maintenance theme from cache).
    backdrop_add_http_header('Status', '500 Internal Server Error');

    // Another uncaught exception was thrown while handling the first one. If we
    // are displaying errors, then do so with no possibility of a further
    // uncaught exception being thrown.
    if (error_displayable()) {
      print '<h1>Additional uncaught exception thrown while handling exception.</h1>';
      print '<h2>Original</h2><p>' . _backdrop_render_exception_safe($exception) . '</p>';
      print '<h2>Additional</h2><p>' . _backdrop_render_exception_safe($exception2) . '</p><hr />';