Hi,
Is it possible to throw the exception if the final Retry Fails? I am using the WaitAndRetryAsync, but I wish to throw the exception if the final retry throws and exception.
I can see the CircuitBreaker throws the exception but is it possible waiting before retries?
Thanks in advance!
Hi @grik001
Is it possible to throw the exception if the final Retry Fails?
That is exactly what the library does by default - see how retry works in the wiki.
Let me know if I've not understood the question, and you're after something slightly different!
I will test this again, but I am sure that WaitAndRetryAsync was blocking the exception even if the last try does not succeed.
Hi @grik001 . Happy to look at any code if you can post a repro. Here within Polly is a unit test demonstrating that WaitAndRetryAsync does rethrow the final exception.
Couple of things that could cause a final exception not to be rethrown:
.ExecuteAsync(...), like any async API, returns Task. If the result of .ExecuteAsync(...) isn't awaited, then the exception will remain captured on the Task rather than rethrown..ExecuteAndCaptureAsync(...), then the design intent of that is to capture any final exception into the FinalException property. .ExecuteAndCaptureAsync(...) captures any final exception, whereas .ExecuteAsync(...) rethrows it.@reisenberger
Hi, I confirmed that you are right, sorry for wasting your time and thanks for the explanation
No problem @grik001 ! Let us know if there is anything else we can help with.
Most helpful comment
Hi @grik001 . Happy to look at any code if you can post a repro. Here within Polly is a unit test demonstrating that WaitAndRetryAsync does rethrow the final exception.
Couple of things that could cause a final exception not to be rethrown:
.ExecuteAsync(...), like any async API, returnsTask. If the result of.ExecuteAsync(...)isn'tawaited, then the exception will remain captured on theTaskrather than rethrown..ExecuteAndCaptureAsync(...), then the design intent of that is to capture any final exception into theFinalExceptionproperty..ExecuteAndCaptureAsync(...)captures any final exception, whereas.ExecuteAsync(...)rethrows it.