跳轉到內容

WebObjects/Web 應用程式/開發/自定義錯誤處理

來自華夏公益教科書

異常頁面

[編輯 | 編輯原始碼]

要提供在丟擲異常時處理自定義錯誤的處理程式,請覆蓋該方法

 public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { }

例如

 public WOResponse handleException(Exception _exception, WOContext _context) {
   Session session = (Session) _context.session();
   // do something to notify user of exception, maybe put a message in the session here ...
   WOResponse response;
   if (/* you can't handle exception*/) {
     response = super.handleException(_exception, _context);
   }
   else {
     response = pageWithName(YourExceptionPage.class.getName(), _context).generateResponse();
   }
   return response;
 } 

會話過期

[編輯 | 編輯原始碼]

要提供在丟擲異常時處理自定義錯誤的處理程式,請覆蓋該方法

 public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {

例如

 public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {
   Session session = (Session) _context.session();
   // do something to notify user of exception, maybe put a message in the session here ...
   WOResponse response = pageWithName(YourErrorPage.class.getName(), _context).generateResponse();
   return response;
 }

您的請求產生了錯誤

[編輯 | 編輯原始碼]

Chuck Hill

[編輯 | 編輯原始碼]

當在 DirectAction 中引發異常時,此訊息從 WO 5.2 開始出現,但僅在已部署的應用程式中出現。以下發生了什麼

WODisplayExceptionPages true 或 false 用於啟用或停用為直接操作請求生成 WOExceptionPages。預設情況下,在開發模式下為 true,在部署模式下為 false。

來自http://developer.apple.com/documentation/WebObjects/WOAppProperties/AppProperties/chapter_1_section_1.html

如果要返回的頁面在 appendToResponse 期間丟擲,並且應用程式已部署,則只會顯示一個空白頁面,其中包含“您的請求產生了錯誤”幾個字。

要避免這種情況,請將此內容新增到啟動引數中

 -DWODisplayExceptionPages=true

或者將應用程式類中的 main 方法更改為如下所示

 public static void main(String argv[]) {
   System.setProperty("WODisplayExceptionPages", "true");
   WOApplication.main(argv, Application.class);
 }

如果您將其放在建構函式中,則此方法無效。

華夏公益教科書