目录

Drupal - 错误处理( Error Handling)

在本章中,我们将研究Drupal错误处理,以便在Drupal站点上管理错误消息。

错误处理是一个检测和查找错误分辨率的过程。 它可以是编程应用程序错误或可传递错误。

以下步骤描述了如何在Drupa中管理错误消息 -

Step 1 - 转到“ Configuration ,然后单击“ Logging and errors

Drupal错误处理

Step 2 - 将显示“ Logging and errors页面,如以下屏幕所示。

Drupal错误处理

以下是前面屏幕中显示的字段的详细信息 -

  • Error messages to display - 它指定要在Drupal站点上显示的错误消息。

    • None - 此选项不显示任何错误消息。

    • Errors and warnings - 此选项仅显示与错误和警告相关的消息。

    • All messages - 此选项指定要在站点上显示的所有类型的错误消息,例如错误,警告等。

  • Database log messages to keep - 它指示要在数据库日志中保留的最大消息数。

Drupal使用_drupal_exception_handler ($exception)函数来处理站点上的错误。 这些错误不会包含在try/catch块中。 异常处理程序退出时,脚本不会执行该函数。

_drupal_exception_handler的代码如下 -

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/>';
      }
   }
}

必须在每个Drupal请求上使用该函数。 该函数出现在文件includes/bootstrap.inc中的第2328行。

有两个对_drupal_exception_handler字符串引用,例如bootstrap.inc文件中存在_drupal_bootstrap_configuration()_drupal_get_last_caller文件中存在_drupal_get_last_caller 。 这两个文件都存在于'includes'文件夹中。

↑回到顶部↑
WIKI教程 @2018