Mega Code Archive

 
Categories / C# Tutorial / Language Basics
 

Catch statement without exception variable

using System; class MainClass {    static void Main()    {       int x = 10, y = 0;              try {                  x = x/y;               }catch (System.IndexOutOfRangeException) {                  Console.WriteLine("catch clause");               } finally {                  Console.WriteLine("finally clause");               }    } } Unhandled Exception: System.DivideByZeroException: Attempted to divide by zero. at MainClass.Main() finally clause