Mega Code Archive

 
Categories / C# Tutorial / Language Basics
 

Exception handling with trying and catching

using System; class MainClass{          public static void Main(){         Console.WriteLine("Before catch");         int Zero = 0;         try {             int j = 22 / Zero;         } catch (Exception e) {             Console.WriteLine("Exception " + e.Message);         }                  Console.WriteLine("After catch");     } } Before catch Exception Attempted to divide by zero. After catch