GWT RPC - Checked exception handling

143 views
Skip to first unread message

Alex

unread,
Sep 9, 2011, 4:43:23 AM9/9/11
to Google Web Toolkit
Hi guys,

I am stuck on the gwt rpc exception handling. I got a service method
that throws a checked exception. My AsyncCallback forces me to add two
methods: onFailure(Throwable caught) and onSuccess. If the checked
exception is thrown, the callback method onFailure is invoked.

-> So far everything is ok, but eclipse forces me to add a throw/catch
block around the ServiceCall and to catch the checked exception. Even
when the exception is thrown, this code is never called as the
exception goes directly into onFailure. How can I avoid adding the try/
catch block? It is somewhat useless to me...

Regards,
Alex

Thomas Broyer

unread,
Sep 9, 2011, 4:54:10 AM9/9/11
to google-we...@googlegroups.com
You should declare thrown exceptions only on the "sync" interface, not the "async" one.

Sync:
   boolean doFoo(int bar) throws MyException;

Async:
   void doFoo(int bar, AsyncCallback<Boolean> callback); // no "throws" clause here

Alex

unread,
Sep 9, 2011, 4:58:35 AM9/9/11
to Google Web Toolkit
Ahhhh alright! I knew there must have been some stupid mistake. Thank
you!

Alex

unread,
Sep 9, 2011, 5:02:08 AM9/9/11
to Google Web Toolkit
Someone should report this, the AsyncCallback in the demo application
has a throws declaration too:

void greetServer(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;

Reply all
Reply to author
Forward
0 new messages