-1

I have the following code:

 var policyResult = await _circuitBreakerPolicy.ExecuteAndCaptureAsync(async () =>
     {
         return await  configuredTaskAwaitable;
     });

return policyResult.Result;

When the circuit breaker is in Open state, the result is simply null, and no exception is thrown. Shouldn't it throw an exception if the circuit is opened?

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
ryudice
  • 36,476
  • 32
  • 115
  • 163

1 Answers1

8

.ExecuteAndCaptureAsync() is designed to capture any exceptions thrown into the policyResult.FinalException property. You should find the exception there. (The policyResult.Result property is null (strictly: default(TResult) for whatever TResult) because indeed no result was obtained.)

If you want execution through the policy to leave any exception as originally thrown rather than capture it, use the straight .ExecuteAsync(...)

mountain traveller
  • 7,591
  • 33
  • 38