I'm pretty new with Polly and I'm trying to understand how works, starting from the very basics.
To test the retries I tried to create a code (Print) that has 33% to generate a DivideByZeroException
. When the error is generated it raise up to policy.Execute
seems don't managed by Polly.
Someone can help me to adjust this code? I'm using .Net Framework 4.7.2.
using System;
using Polly;
class Program
{
static void Main(string[] args)
{
var policy = Policy
.Handle<DivideByZeroException>()
.Retry();
policy.Execute(() => Print());
Console.ReadKey();
}
private static void Print()
{
var rand = new Random();
int a = rand.Next(1000, 2000);
int b = rand.Next(0, 2);
Console.WriteLine("a = {0} - b {1}", a, b);
int c = a / b;
Console.WriteLine("c = {0}", c);
}
}