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:
- I have declared my custom RuntimeException (which would indicated that I need to retry):
public class RestCallRetryException extends RuntimeException
- 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;
- I have declared the retry method to handle it:
@Recover InquiryResponse recover(RestCallRetryException e) throws RestCallException;
- 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?