On Feb 2, 9:56 am, Fotos Georgiadis <[email protected]> wrote: > Hi, > > I have a question about the proper use of error handling code with > RequestBuilder. I can't figure out what's gonna happen, when something > goes wrong, and the proper way to handle such situations. > > I've already searched this group's archives and googled it a bit but > couldn't find anything relevant (or even remotely associated). The > documentation (javadoc) is not clarifying enough (IMHO). > > Some (pretty much standard) example code: > > // Create new request builder > RequestBuilder builder = new RequestBuilder > (RequestBuilder.POST, configuration.LOGIN_URL()); > > // set other headers, params, etc. > > // Send the request > try { > request = builder.sendRequest(data, new RequestCallback() > { > > public void onError(Request request, Throwable exception) > { > // Handle errors: dispatch a message on the event bus to show > an > error message > } > > public void onResponseReceived(Request request, Response > response) { > // Parse response according to HTTP status code... > }); > } catch (RequestTimeoutException e) { > // Do we have to handle the error again? Or just ignore it > since we handled it in onError? > } catch (RequestException e) { > // Ditto... > } > > The question is ... if, for example, a RequestTimeoutException happens > what's the sequence of things? > > Case 1: > onError() gets called AND then a RequestTimeoutException is thrown and > handled by the external try / catch block? > > Case 2: > Only the exception is being thrown without calling onError() method of > the callback class? > > Case 3: > The onError() method is called and no exception is being thrown? > > Or which case happens depends on external factors (browser, OS, other > things)?
It can only be case 3 because of the asynchronous nature of the call. When the timeout "fires", you're already passed the "catch" close. The send() will throw only when the browser refuses to even make the request, i.e. in the case of a cross-origin request (well, except in recent browsers that support so-called "CORS": namely Chrome and FF3.5+; in those browsers, you'll eventually have onError called if the server doesn't allow the cross-origin request) -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
