2011-03-16 94 views
0

你好,我在GWT有一段代碼,我的一位高級同事寫了這段代碼。Handlling GWT呼叫失敗

public void onFailure(Throwable caught) { 

    if (caught instanceof RuntimeException) { 

     if (caught instanceof StatusCodeException 
      && caught.getMessage().contains(
       "<title>Error 500 unAuthorized</title>")) { 
      MessageBox 
       .alert("Session has been expired. Press Ok to redirect to Login page."); 
      History.newItem(HistoryToken.INDEX_PAGE.toString()); 
     } else { 
     MessageBox 
      .alert("An exception has occured.Press Ok to continue."); 
     } 

    } else if (caught instanceof InvocationException) { 
     MessageBox 
      .alert("Sorry... Some error occured while reaching to server."); 

    } 
} 

什麼是執行else if (caught instanceof InvocationException) {塊時呼叫服務器失敗的可能性有多大?

我認爲else if (caught instanceof InvocationException)在任何情況下都不會被執行。 有何建議?

回答

1

由於InvocationException是RuntimeException的子類(如docs所述),因此您是正確的。

順便說一句,有沒有什麼理由你的高級同事做getMessage的字符串比較,而不是用getStatusCode()檢查狀態碼? (See here

+0

感謝您的回覆。這傢伙離開了這家公司。 – 2011-03-16 11:30:48