Is there a way in Polly to retry all exceptions apart from those which are specified.. for example:
var p = Policy .Handle<HttpListenerException>(e => !(e.NativeErrorCode == 1)) .Or<Exception>() .RetryAsync();
Here i have picked a slightly contrived situation where i would want to NOT retry when the NativeErrorCode == 1
?
I initially hoped that this will retry if any value other than 1, and any other Exception dealt with by the .Or<Exception>()
..
What is actually happening, is that the .Or<Exception>
will also catch the NativeErrorCode == 1
, even though it was excluded from above? I think..
One option i considered, but not tested... (no error checking ;p)
var p = Policy .Handle<Exception>(e => SomethingMoreComplex(e) == true) .RetryAsync();private bool SomethingMoreComplex(Exception e){ if (e is HttpListenerException t) { if (t.NativeErrorCode == 1) return false; } return true;}
is that threadsafe? :|