Efficient Error Handling in Drupal: A Comprehensive Guide

thumb_up 1  ·  sell Drupal error management, Handling errors in Drupal, Troubleshooting issues in Drupal

In this chapter, we will study about Drupal error handling for managing error messages on Drupal site.

Error Handling is a process of detection and finding the resolutions for the errors. It can be programming application errors or communicable errors.

The following steps describe how to manage error messages in Drupa −

Step 1 − Go to Configuration and click Logging and errors.

Step 2 − The Logging and errors page will get displayed as shown in the following screen.

Following are the details of the fields as seen in the preceding screen −

  • Error messages to display − It specifies error messages to be displayed on the Drupal site.

    • None − This option doesn't display any error message.

    • Errors and warnings − This option displays only messages related to errors and warnings.

    • All messages − This option specifies all types of error messages such as errors, warnings, etc. to be displayed on the site.

  • Database log messages to keep − It indicates the maximum number of messages to be kept in the database log.

Drupal uses _drupal_exception_handler ($exception) function to handle the errors on the site. These errors will not be enclosed in a try/catch block. The script won't execute the function when an exception handler exits.

The code for _drupal_exception_handler is as follows −

function _drupal_exception_handler($exception) {
   require_once DRUPAL_ROOT . '/includes/errors.inc';
   try {
      // display the error message in the log and return the error messages to the user
      _drupal_log_error(_drupal_decode_exception($exception), TRUE);
   }
   catch (Exception $excp2) {
      // 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($excp2).'</p><hr/>';
      }
   }
}

The function must be used on every Drupal request. This function is present at the line 2328 in the file includes/bootstrap.inc.

There are two string references to _drupal_exception_handler such as_drupal_bootstrap_configuration() present in the bootstrap.inc file and_drupal_get_last_caller present in the errors.inc file. Both these files are present in the ‘includes’ folder.

 

The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.

Was this answer helpful?

Related Articles

description

An Introduction to Drupal

    Drupal is a free and open source Content Management System (CMS) that allows organizing, managing and publishing your content. It is…

arrow_forward
description

Installing Drupal: A Comprehensive Guide

    This chapter provides step-by-step procedure for Drupal installation. Before installing Drupal, the following system requirements are…

arrow_forward
description

Understanding the Drupal Architecture

  Drupal is a platform for web content management which is a powerful tool for building simple and complex sites. In this chapter, we are…

arrow_forward
description

Exploring Drupal's Main Menu Functionality

    In this chapter, we will study how to Create Menus in Drupal. Menus are very important to easily navigate in your website. Menus…

arrow_forward
description

Mastering Drupal's Blocks and Regions

  In this chapter, we will study about Drupal Blocks & Regions. Blocks are container objects that are used to organize your content of…

arrow_forward
arrow_back « Back