Wednesday, August 31, 2011

Re: Inherited exceptions in GWT-RPC

On Aug 26, 12:51 am, Paul Robinson <ukcue...@gmail.com> wrote:
> You shouldn't need to do anything. It should work as you thought. That is, you can throw any subclass of the declared exception(s).
>
> Is there something about BException and CException that stops them from being gwt-serializable?

No, and in fact, if I declare them explicitly, then GWT throws them as-
is, rather than wrapping them in InvocationException.

> Alternatively, maybe it's because AException extends RuntimeException, and is therefore not a checked exception. It could be that, being an unchecked exception, GWT silently drops it (or rather, its subclasses) from the list of exceptions to expect.
>
> Try "AException extends Exception" instead.

That's what I'm afraid of. It looks like GWT will only allow declared
exceptions, and not subclasses. I don't want to extend Exception,
because it means the Java compiler will force me to handle the
exception explicitly:

try {
service.remoteMethodThatThrowsException( ... , new
AsyncCallback<Void>() {
@Override
public void onFailure( Throwable caught ) { ... }

@Override
public void onSuccess( Void result ) {...}
} );
} catch (Exception e) {}

That sort of defeats the purpose for handling the exception in the
onFailure() method to begin with.

> HTH
> Paul
>
> On 25/08/11 21:09, Ryan wrote:
>
>
>
>
>
>
>
> > My understanding is that in GWT-RPC, if a service throws an exception
> > declared in the signature, then GWT will report that exception back to
> > the client as-is.  If it's any other exception that's thrown, then GWT
> > wraps it in an InvocationException.
>
> > I have a hierarchy of exceptions that could get thrown in my
> > application.  For example:
>
> > class AException extends RuntimeException {}
> > class BException extends AException {}
> > class CException extends AException {}
>
> > If I declare AException in the client, and throw it in the server,
> > then the onFailure() method gets called with AException as expected.
> > However, if I declare AException in the client, but throw either of
> > the two child classes in the server, GWT wraps it in an
> > InvocationException.
>
> > What is the best way to intercept ALL the child exceptions?  The only
> > thing I can see so far is declaring each possible child exception in
> > the service signature, but that seems very brittle to me.
>
> > Thanks,
> > Ryan

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment