try{ int res = 0; for (int i = 2; i >= 0; i--) res = 10 / i; // <-- Will get an exception of Divide by Zero when i = 0}catch (Exception){ System.Console.WriteLine("Caught an exception"); // Will catch the exception }