Handlling GWT呼叫失败

问题描述:

你好,我在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)在任何情况下都不会被执行。 有何建议?

由于InvocationException是RuntimeException的子类(如docs所述),因此您是正确的。

顺便说一句,有没有什么理由你的高级同事做getMessage的字符串比较,而不是用getStatusCode()检查状态码? (See here

+0

感谢您的回复。这家伙离开了这家公司。 – 2011-03-16 11:30:48