0

EDIT: I read the linked topic (Getting UndeclaredThrowableException instead of my own exception) carefully but it does not answer my question - that ticket suggests to declare the checked exception in the intercepted method which is what I already did.

I'm trying to use the Spring Retry mechanism and want to throw my custom checked exception in the resolve method but it fails with the UndeclaredThrowableException. Here is what I do:

  1. I have declared my custom RuntimeException (which would indicated that I need to retry):

public class RestCallRetryException extends RuntimeException

  1. I throw this runtime exception in the implementation of the following method then:

@Retryable(value = RestCallRetryException.class, maxAttempts = 2) InquiryResponse postInquiry(InquiryRequest inquiryRequest) throws RestCallException;

  1. I have declared the retry method to handle it:

@Recover InquiryResponse recover(RestCallRetryException e) throws RestCallException;

  1. As you can see, I also have RestCallException which is a checked exception being thrown in recover:

public class RestCallException extends Exception

I throw RestCallException in the implementation of recover(RestCallRetryException e) and get the UndeclaredThrowableException. I don't understand why this happens. I would have understood this would be the case, had I not declared that the method marked with @Retryable (postInquiry) throws the RestCallException - but this is all declared as you can see in my code snippets. What am I missing here?

  • Check this answer as it may help in your case https://stackoverflow.com/a/5490372/2710264 – wawek Mar 29 '21 at 06:57
  • @Lino - please reconsider closing the ticket. I stated my explanation of why I think it's not a duplicate. – Daniel Piotrowski Mar 29 '21 at 07:32
  • @DanielPiotrowski Please also provide the stacktrace, as far as I understand your question, the method *handling* the retry is a method from spring and *that* one doesn't declare your `RestCallException` (because it **can't** declare it) – Lino Mar 29 '21 at 07:54
  • Please provide a full [MCVE](https://stackoverflow.com/help/mcve), ideally a little GitHub project incl. Maven build, then I will reopen the question and also look into it. – kriegaex Apr 02 '21 at 01:42

0 Answers0