Monday, September 13, 2010

Unchecked exceptions from server to client

Hi,

I have this;

public abstract class CreateException extends RuntimeException implements Serializable {
}

Notice that I extend from RuntimeException, making it an unchecked exception.

Then I have these two;

public class DuplicateEmailCreationException extends CreateException {
}

public class DuplicatePhoneCreationException extends CreateException {
}

My service is this one;

@RemoteServiceRelativePath("AccountService")
public interface AccountService extends RemoteService {
public void createAccount(String phone, String email);
}

Notice I don't declare my CreateException using the "throws" keyword.

Now I would expect my view to work. It's this one;

...
accountServiceAsync.createAccount(tbPhone.getValue(), tbEmail.getValue(), new AsyncCallback<Void>() {
public void onSuccess(Void result) {
}

public void onFailure(Throwable exception) {
if ( exception instanceof DuplicatePhoneCreationException) {
// handle it
}
else {
if (exception instanceof DuplicateEmailCreationException) {
// handle it
}
}
}

...

However, it does not work. But if I add the "throws CreateException" in the AccountService's createAccount method, it works fine.

The whole point with unchecked exceptions, is that I don't have to define them everywhere. Is this not supported ? Or what am I doing wrong here ?

Thanks,

:-) Kasper

--
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