0

What is the requirement in a Service implementation so that the ErrorCallback will be able to print the error message on the UI like.

I tried injecting a ErrorCallback in the Service call code, and when I print the Message object its null.

What should be the Service implementation look like, should I put throws SomeException on the implementation method? Or?

myService.call(new RemoteCallback<String>() {
    @Override
    public void callback(String response) {
        Multimap<String, String> state =  ArrayListMultimap.create();
        state.put("hash", response);
        submit.go(state);
    }
}, new ErrorCallback() {
    @Override
    public boolean error(Message message, Throwable throwable) {
        throwable.printStackTrace();
        Window.alert("Error: " + message);
        return false;
    }
}).createmy(my);
quarks
  • 33,478
  • 73
  • 290
  • 513
  • Can you edit the question and show the code that isn't working for you? – Jonathan Fuerth May 15 '13 at 19:40
  • What should be the implementation of myService method createmy() look like? Should it contain a 'throws Exception' for the ErrorCallback to return non null message? – quarks May 15 '13 at 19:47

1 Answers1

0

Your code should work as stated in the question. The exception thrown by the remote service should be delivered to you in the throwable parameter to your ErrorCallback.error() method.

You only need to put a throws clause on the remote interface if you want to throw a checked exception. Unchecked exceptions should work as you've done it. In fact, there is a disadvantage to declaring checked exceptions on remote interfaces: you will have to surround your RPC calls with a useless try/catch block, like this:

@Remote public interface MyService {
  Result dangerousOperation() throws MyCheckedException;
}

and the calling code:

try {
  myService.call(new RemoteCallback<Result>() {
    @Override
    public void callback(final Result result) {
      Window.alert("Yay, got a result: " + result);
    }
  },
  new BusErrorCallback() {
    @Override
    public boolean error(Message message, Throwable throwable) {
      Window.alert("Got an exception from the remote service: " + throwable);
      return false;
    }
  }).dangerousOperation();
}
catch (MyCheckedException e) {
  throw new AssertionError(); // can't happen: caller stub won't throw this
}

So you're probably better off with the unchecked exception.

Jonathan Fuerth
  • 2,080
  • 2
  • 18
  • 21