private static void Main()
 {
     var ehd = new ExceptionHandledDelegate
         {
             codeBlock = () => { throw new ArgumentException("An argument exception has been thrown"); },
             ExceptionHandlers = new Dictionary<Type, ExceptionHandledDelegate.ExceptionCatcher>
             {
                 {typeof (ArgumentException), exception => Console.WriteLine("Check your arguments")},
                 {typeof (Exception), exception => Console.WriteLine("An exception has been thrown")}
             }
         };
         ehd.Run();
         ehd.codeBlock = () => { throw new Exception("An exception has been thrown"); };
         ehd.Run();
         Console.ReadLine();
 }
Ejemplo n.º 2
0
    private static void Main()
    {
        var ehd = new ExceptionHandledDelegate
        {
            codeBlock         = () => { throw new ArgumentException("An argument exception has been thrown"); },
            ExceptionHandlers = new Dictionary <Type, ExceptionHandledDelegate.ExceptionCatcher>
            {
                { typeof(ArgumentException), CommonHandlers.ArgumentHandler },
                { typeof(DivideByZeroException), CommonHandlers.DivZeroHandler },
                { typeof(Exception), exception => Console.WriteLine("An exception has been thrown") }
            }
        };

        ehd.Run();
        ehd.codeBlock = () => { throw new Exception("An exception has been thrown"); };
        ehd.Run();
        ehd.codeBlock = () => { var denom = 0; Console.WriteLine(100 / denom); };
        ehd.Run();
        Console.ReadLine();
    }