Handlling GWT call failure
Hello I have a piece of code in GWT, A senior colleage of mine has written this code.
public void onFailure(Throwable caught) {
if (caught instanceof RuntimeException) {
if (caught instanceof StatusCodeException
&& caught.getMessage().contain开发者_Python百科s(
"<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.");
}
}
What are the chances of executing else if (caught instanceof InvocationException) {
block when call failed on server ?
I think else if (caught instanceof InvocationException)
will not get executed in any case.
Any Suggestions ?
Because InvocationException is a subclass of RuntimeException (as the docs say), you are correct.
BTW, is there any reason your senior colleague does a string comparison on getMessage instead of checking the status code with getStatusCode()? (See here)
精彩评论