This is what the onFailure(Throwable t)
method on AsyncCallback
is for. This method is called when the RPC fails for any reason, including (but not limited to) loss of connection.
Since the Throwable
that gets passed into onFailure()
can be anything, the pattern used in the docs is:
public void onFailure(Throwable caught) {
// Convenient way to find out which exception was thrown.
try {
throw caught;
} catch (IncompatibleRemoteServiceException e) {
// this client is not compatible with the server; cleanup and refresh the
// browser
} catch (InvocationException e) {
// the call didn't complete cleanly
// other Throwables may be caught here...
} catch (Throwable e) {
// last resort -- a very unexpected exception
}
}
Specifically, a lack of internet connection will cause an InvocationException
to be passed to onFailure()