Drupal 错误处理
在本章中,我们将研究用于管理 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 '<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 的字符串引用,例如
_drupal_bootstrap_configuration() 存在于
bootstrap.inc 文件和
_drupal_get_last_caller b> 存在于 errors.inc 文件中。这两个文件都位于
‘includes’ 文件夹中。