A try, catch, and finally block without Exception class declaration
using System;
class MainClass
{
public static void Main()
{
try
{
int zero = 0;
Console.WriteLine("In try block: attempting division by zero");
int myInt = 1 / zero;
Console.WriteLine("You never see this message!");
}
catch
{
Console.WriteLine("In catch block: an exception was thrown");
}
finally
{
Console.WriteLine("In finally block: do any cleaning up here");
}
}
}
Output
In try block: attempting division by zero
In catch block: an exception was thrown
In finally block: do any cleaning up here