在本章中,我们将研究Drupal错误处理以管理Drupal站点上的错误消息.
错误处理是一个检测和查找错误分辨率的过程.它可能是编程应用程序错误或可传播错误.
以下步骤描述了如何管理Drupa中的错误消息 :
步骤1 : 转到配置,然后单击记录和错误.
步骤2 : 将显示记录和错误页面,如下面的屏幕所示.
以下是前面屏幕中显示的字段的详细信息 :
要显示的错误消息 : 它指定要在Drupal站点上显示的错误消息.
无 : 去;此选项不显示任何错误消息.
错误和警告 : 此选项仅显示与错误和警告相关的消息.
所有消息 : 此选项指定要在网站上显示的所有类型的错误消息,例如错误,警告等.
要保留的数据库日志消息 : 它表示要在数据库日志中保留的最大消息数.
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 'Additional uncaught exception thrown while handling exception.
'; print 'Original
'. _drupal_render_exception_safe($exception).'
'; print 'Additional
'. _drupal_render_exception_safe($excp2).'
'; } }}
每个Drupal请求都必须使用该函数.此函数出现在文件 includes/bootstrap.inc 中的第2328行.
有两个字符串引用 _drupal_exception_handler 等as _drupal_bootstrap_configuration()出现在 bootstrap.inc 文件中, _drupal_get_last_caller 出现在errors.inc文件中.这两个文件都存在于'includes'文件夹中.