【问题标题】:Polly ExecuteAndCaptureAsync not throwing exceptions when circuit breaker is openPolly ExecuteAndCaptureAsync 在断路器打开时不抛出异常
【发布时间】:2017-04-04 23:04:56
【问题描述】:

我有以下代码:

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

return policyResult.Result;

当断路器处于打开状态时,结果简单地为空,不会抛出异常。如果电路打开,它应该抛出异常吗?

【问题讨论】:

    标签: c# circuit-breaker polly


    【解决方案1】:

    .ExecuteAndCaptureAsync()designed to capture any exceptions thrown 进入 policyResult.FinalException 属性。你应该在那里找到异常。 (policyResult.Result 属性是 null(严格来说:default(TResult)TResult),因为确实没有得到任何结果。)

    如果您希望通过策略执行以保留最初引发的任何异常而不是捕获它,请直接使用 .ExecuteAsync(...)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-05
      • 2014-05-20
      相关资源
      最近更新 更多