Retry if exception is not TimeoutException

CSharp · Console

/Program.cs

using System;
using Polly;
					
public class Program
{
	public static void Main()
	{
		var retry = Policy
			.Handle<Exception>(ex => !(ex is TimeoutException))
			.WaitAndRetry(2, _ => TimeSpan.FromSeconds(1));
		
		retry.Execute(WrappedMethod);
	}
	
	public static int counter = 0;
	public static void WrappedMethod()
	{
		Console.WriteLine("The wrapped method is called");
		if(counter++ == 1) 
			throw new TimeoutException();
		throw new ArgumentException();
	}
	
	
}
;