spring-retry icon indicating copy to clipboard operation
spring-retry copied to clipboard

Improve Javadoc for `setThrowLastExceptionOnExhausted` of `RetryTemplate`

Open fabriziocucci opened this issue 7 years ago • 4 comments

Description

As already reported here, I was too a bit surprised to discover that throwLastExceptionOnExhausted has no effect on stateless retries.

I'm not sure I fully understand the logic behind the current behaviour but it would be nice to, at very least, fix the current javadoc by explicitly mentioning that.

fabriziocucci avatar Dec 09 '18 17:12 fabriziocucci

A stateless retry always throw the last exception (if it is an Exception) I think. Isn't that kind of what you want if you are setting that flag anyway?

dsyer avatar Dec 15 '18 11:12 dsyer

@dsyer thanks for your reply.

The current behavior for stateless retry seems to be:

  • throwLastExceptionOnExhausted=true -> last exception is thrown
  • throwLastExceptionOnExhausted=false -> last exception is thrown

So, in any case, the last exception is always thrown and this means that the flag has no effect on stateless retries.

From a user prospective, I would have somehow expected: throwLastExceptionOnExhausted=false -> ExhaustedRetryException is thrown.

fabriziocucci avatar Dec 15 '18 11:12 fabriziocucci

I see what you mean. I'm not sure why you would want to set it to false in that case (that's the default anyway). Do you have an actual use case. If not, and this is really just a nitpick about the javadocs, then feel free to send a pull request clarifying the situation/

dsyer avatar Dec 15 '18 17:12 dsyer

Hello, I actually have a case where I wanted ExhaustedRetryException to be thrown but couldn't understand why it wasn't. I created an unique RetryTemplate which was called several times, and I wanted to catch on top of them if my exception came from a RetryTemplate or not.

Would it be possible to make this option works on stateless retry too ?

I'm actually throwing an exception wrapper from a listener as a workaround

Rajh avatar Oct 18 '19 14:10 Rajh