Can someone please explain why the below code is failing on first attempt and throwing unhandled exception? Much appreciated.
using Polly;
using System;
using System.Threading;
namespace TestPolly
{
class Program
{
static void Main(string[] args)
{
Policy.Handle<DivideByZeroException>().Retry(10).Execute(() => DoSomething(0));
}
private static void DoSomething(int num)
{
Thread.Sleep(1000);
Console.WriteLine("Doing division");
var y = 2 / num;
}
}

You are just seeing the debugger break on the Exception, as explained in detail in this article on the Polly wiki.
Can someone please explain why the below code is failing on first attempt and throwing unhandled exception?
The code is not failing nor throwing an unhandled exception. When you press F5 (or click Continue in the debugger) to continue debugging, you will see execution continue - and that the exception is being handled by the policy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With