Drupal - 錯誤處理



在本章中,我們將學習關於 Drupal 錯誤處理,以管理 Drupal 站點上的錯誤訊息。

錯誤處理是一個檢測和查詢錯誤解決方案的過程。它可以是程式設計應用程式錯誤或可通訊錯誤。

以下步驟描述瞭如何在 Drupa 中管理錯誤訊息:

步驟 1 - 轉到配置並點選日誌和錯誤

Drupal Error Handling

步驟 2 - 將顯示日誌和錯誤頁面,如下面的螢幕截圖所示。

Drupal Error Handling

以下是前面螢幕截圖中欄位的詳細資訊:

  • 要顯示的錯誤訊息 - 它指定要在 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 存在於 errors.inc 檔案中。這兩個檔案都位於“includes”資料夾中。

廣告

© . All rights reserved.