0

How to get exception from server side, if my service method throws new MyException("Some reason"); I would like to get MyException in onFailure method, but actually I got StatusCodeException. Can I get MyException in order to show error msg on UI : Window.alert(exception.getMessage()); -> prints : "Some reason"

@RemoteServiceRelativePath("reportService.rpc")
public interface ReportService extends RemoteService {
    void saveReport(ReportDTO reportDTO) throws MyException;
}

 @Override
    public void saveReport(ReportDTO reportDTO) throws MyException {
        //Report report = ReportFunc.INST.apply(reportDTO);
        //reportRepository.save(report);
        throw new MyException("Some reason");
    }

 reportServiceAsync.saveReport(reportDTO, new AsyncCallback<Void>() {
                    @Override
                    public void onSuccess(Void result) {
                        Window.alert("Successfully saved");
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        Window.alert(e.getMessage());
                    }
                });

class MyException extends RuntimeException implements Serializable{
  ....
}
3
  • Just for clarification: Do you get your message as a StatuscodeException? Which is the Statuscode? 500 or 404? Commented Dec 21, 2014 at 16:01
  • 500 exactly, it's means that error occurred on server side. Commented Dec 21, 2014 at 19:26
  • If you get a 500 you should have something in the server logs, but I'd bet it's not directly related to the thrown exception. Commented Dec 21, 2014 at 21:04

1 Answer 1

1

Your exception should extend Exception, not RuntimeException.

Sign up to request clarification or add additional context in comments.

5 Comments

I have done this, but still have the same StatusCodeException
I changed to extends Exception. It's a pity, but I have the same error 500 Internal Server Error StatusCodeException
I have changed to IOException and the same error occurred.
Maybe this exception is thrown for another reason? Can you make sure that it is thrown by this code line?
Oh my GOD, Andrei you are right, I am mistaken. Now it fixed, everything is ok. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.