Error Handling in GWT

119 views
Skip to first unread message

Cherian George(GWT Newbie)

unread,
Oct 17, 2007, 12:39:24 PM10/17/07
to Google Web Toolkit, cherian...@gamil.com
Hello,

I have a situation where an Exceptions happens in the Remote service
implementation. I caught that exception and re-throw it to the client
in the hope that the Asynch call would fail and that OnFailure method
of the call back object would execute . But it does not happen instead
the onSucess method executes .

Why ?.

How should I propogate an error from the remore service back to the
UI.

Here is the code

public ArrayList GetQueuesList(){
System.out.println("In Here I am");
try {
System.out.println("In Here I am1");
CacheInterface c = new CacheInterface(url,"Admin","","");
ProDataGraphHolder queuelist = new ProDataGraphHolder();
c.getqueueslist(queuelist);
System.out.println("In Here I am2");
// Marshal the Data out of the DataGraph into a Results List
ProDataGraph queueGraph;

queueGraph = queuelist.getProDataGraphValue();
System.out.println("In Here I am3");
if (queueGraph.getProDataObjects(0) == null) {throw new
Exception("Error Communiucation with Appserver");}
return (ArrayList) queueGraph.getProDataObjects(0);

}
catch(Exception e)
{
System.out.println("Error - " + e.toString());
throw new InvocationException("Error in executing the API");
}
finally {
return null;
}
}

abickford

unread,
Oct 17, 2007, 2:09:13 PM10/17/07
to Google Web Toolkit
First off, you are catching your own exception. i don't think this
was your intent.

Secondly, you will always return null. the finally block will execute
before the method returns. For example:

public class TestClass {
public static void main(String[] args) {
System.out.println(test());
}

public static String test() {
try {
return "try";
} catch (Exception e) {
return "catch";
} finally {
return "finally";
}
}
}

will always return the string "finally".

On Oct 17, 12:39 pm, "Cherian George(GWT Newbie)"

abickford

unread,
Oct 17, 2007, 2:14:02 PM10/17/07
to Google Web Toolkit
Oh, I see what you are doing now w/catching your own exception. That's
legit. But returning null in the finally block makes it so you are
effectively swallowing the exception and always returning null no
matter what happens in he try or catch blocks.

Reinier Zwitserloot

unread,
Oct 18, 2007, 4:10:28 AM10/18/07
to Google Web Toolkit
Indeed, the finally is the cause.

GWT can transfer any thrown exceptions to the client side, provided
they implement IsSerializable. At least, that's how it worked in GWT
1.3. Now that just 'serializable' is required, I'm no longer sure
about how it works. (Throwable is itself Serializable, but I'm 100%
certain that GWT doesn't take all runtime exceptions in the classpath
and compile them, that would be an enormous waste, yet it would be
required to handle this stuff transparantly). Possibly you need to
explicitly declare them on the 'throws' line.

On Oct 17, 6:39 pm, "Cherian George(GWT Newbie)"

Reply all
Reply to author
Forward
0 new messages