How to pass exception from Server to Client side in GWT RPC

1.3k views Asked by At

I am creating a RPC call using Async method in GWT. I have to check if there is any error on my Server side. Can I catch the exceptions of the server side on the Client side in GWT RPC?

2

There are 2 answers

0
Thomas Broyer On BEST ANSWER

The exceptions have to be declared in a throws clause in your RemoteService interface's methods, and have to be serializable by GWT-RPC under the same conditions as any other transported class.

You'll receive the exception in your AsyncCallback's onFailure. See also the javadoc for AsyncCallback.


EDIT: actually, it happens that I just said the same thing that the doc already says: http://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideHandlingExceptions

3
Andrei Volgin On

Yes, you can. Just make sure that your exception implements Serializable:

public class LoginException extends Exception implements Serializable {

    public LoginException() {
    }
}