Finally
using System;
/* A finally block of code always executes,
* whether or not an exception has occurred. */
public class FinallyDemo
{
static void Main(String[] args)
{
int[] a = new int[] { 1, 2 };
try
{
for (int i = 0; i < 3; i++)
{
Console.WriteLine(a[i]);
}
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("Inside finally block");
}
Console.ReadLine();
}
}
Output:
1
2
System.IndexOutOfRangeException: Index was outside the bounds of the array.