Polly: Policy.Execute question

Created on 24 Apr 2018  Â·  2Comments  Â·  Source: App-vNext/Polly

when Policy.Execute ,must wrap

try{
Policy.Execute()...
}catch(Exception ex){}
flag=1;

if i am not wrap with try catch ,and "flag=1" never run;
if i want deal with the exception by myself?

documentation question

Most helpful comment

@taomylife521 . The three reactive Policy types propagate handled exceptions out of the Policy as follows:

  • Retry policies: rethrow the final exception on to your code, if all tries have failed.
  • CircuitBreaker policies rethrow all exceptions, even handled ones. A circuit-breaker measures the exceptions and decides whether to introduce fail-fast breaking (break the circuit), but rethrows all exceptions.
  • Fallback policies do not by default rethrow handled exceptions.

The wiki pages linked above for each Policy give more information.

For the cases when a policy rethrows an exception, you can either:

  • handle it with your own try / catch; or
  • use .ExecuteAndCapture(...) to capture the result of execution into a PolicyResult, and so avoid an extra try / catch.

I'm not sure if this answers your question. Let us know if you need anything else?

All 2 comments

@taomylife521 . The three reactive Policy types propagate handled exceptions out of the Policy as follows:

  • Retry policies: rethrow the final exception on to your code, if all tries have failed.
  • CircuitBreaker policies rethrow all exceptions, even handled ones. A circuit-breaker measures the exceptions and decides whether to introduce fail-fast breaking (break the circuit), but rethrows all exceptions.
  • Fallback policies do not by default rethrow handled exceptions.

The wiki pages linked above for each Policy give more information.

For the cases when a policy rethrows an exception, you can either:

  • handle it with your own try / catch; or
  • use .ExecuteAndCapture(...) to capture the result of execution into a PolicyResult, and so avoid an extra try / catch.

I'm not sure if this answers your question. Let us know if you need anything else?

Closing. Extra documentation PRd onto readme, in #458

Was this page helpful?
0 / 5 - 0 ratings