function _drupal_exception_handler

Same name in other branches
  1. 9 core/includes/bootstrap.inc \_drupal_exception_handler()
  2. 8.9.x core/includes/bootstrap.inc \_drupal_exception_handler()
  3. 10 core/includes/bootstrap.inc \_drupal_exception_handler()
  4. 11.x core/includes/bootstrap.inc \_drupal_exception_handler()

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.

Parameters

$exception: The exception object that was thrown.

2 string references to '_drupal_exception_handler'
_drupal_bootstrap_configuration in includes/bootstrap.inc
Sets up the script environment and loads settings.php.
_drupal_get_last_caller in includes/errors.inc
Gets the last caller from a backtrace.

File

includes/bootstrap.inc, line 2686

Code

function _drupal_exception_handler($exception) {
    require_once DRUPAL_ROOT . '/includes/errors.inc';
    try {
        // Log the message to the watchdog and return an error page to the user.
        _drupal_log_error(_drupal_decode_exception($exception), TRUE);
    } catch (Exception $exception2) {
        // Add a 500 status code in case an exception was thrown before the 500
        // status could be set (e.g. while loading a maintenance theme from cache).
        drupal_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>' . _drupal_render_exception_safe($exception) . '</p>';
            print '<h2>Additional</h2><p>' . _drupal_render_exception_safe($exception2) . '</p><hr />';
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.