When a remote procedure call fails, the cause falls into one of two categories: an unexpected exception or a checked exception. In either case, you want to handle the exception and, if necessary, provide feedback to the user.
Any number of unexpected occurrences could cause the call to a remote procedure to fail: the network could be down, the HTTP server on the other end might not be listening, the DNS server could be on fire, and so forth.
Another type of unexpected exception can occur if GWT is able to invoke the service method, but the service implementation throws an undeclared exception. For example, a bug may cause a NullPointerException
.
When unexpected exceptions occur in the service implementation, you can find the full stack trace in the development mode log. On the client side, the onFailure(Throwable)
callback method will receive an InvocationException
with the generic message: The call failed on the server; see server log for details.
If you know that a service method might throw a particular type of exception and you want the client-side code to be able to handle it, you can use checked exceptions. GWT supports the throws
keyword so you can add it to your service interface methods as needed. When checked exceptions occur in an RPC service method, GWT will serialize the exception and send it back to the caller on the client for handling.