Reg : Server Logs

346 views
Skip to first unread message

senthil

unread,
Apr 24, 2007, 4:47:18 AM4/24/07
to Google Web Toolkit
Hi ,

I am working newly in GWT, When an exception is thrown , I am unable
to catch the exception in
public void onFailure(Throwable caught) {
Instead, the exception is sent to server logs
The call failed on the server; see server log for details - is shown.
Can any one help me to catch the exception in onFailure() method.I
need the exception message for reference in my code.
Thanks in advance

senthil

unread,
Apr 24, 2007, 4:47:32 AM4/24/07
to Google Web Toolkit

Chad Bourque

unread,
Apr 24, 2007, 10:00:34 AM4/24/07
to Google-We...@googlegroups.com
senthil,
 
When you declare your method signatures in the your synchronous interface, you need to specify that it throws SerializableException:
 
public interface PartService extends RemoteService {
    public CategoryTO[] getCategories(String type) throws SerializableException
}
 
Then, in your implementation class, just rethrow the exception:
 
public class PartServiceImpl extends RemoteServiceServlet implements PartService {
    public CategoryTO[] getCategories(String type) throws SerializableException {
        // code, code, code
        try {
            // more code
        } catch (Throwable caught) {
            throw new SerializableException(caught.getMessage());
        }
    }
}
 
Now, you can catch them in your onFailure method of your AsyncCallback handler:
 
public void onFailure(Throwable caught) {
    Window.alert(caught.getMessage());
}
 
One thing to keep in mind is that you do not put a throws signature in your Async interface, so it would look like this for this example:
 
public interface PartServiceAsync {
    public void getCategories(String type, AsyncCallback callback);
}
 
HTH,
Chad

Miguel Méndez

unread,
Apr 24, 2007, 9:01:35 AM4/24/07
to Google-We...@googlegroups.com
Hi Senthil,

Any exception thrown by your RemoteService method implementation that is not part of its list of checked exceptions will result in an InvocationException on the client.  If you want more specific exceptions you will need to update the method's checked exceptions to include the particular exception.

Note that for an exception to make it back to the client it needs to be GWT serializable; you may need to map whatever exception is being thrown into a GWT serializable exception.

HTH,

On 4/24/07, senthil <asenthi...@corenttech.com> wrote:
Reply all
Reply to author
Forward
0 new messages