Adding Finality with finally - CSharp Custom Type

CSharp examples for Custom Type:try catch finally

Introduction

To execute a block of code regardless of whether the code in a try statement succeeds or fails.

Demo Code

using System;//from   ww w.  ja v a2  s.  c  o  m
class Final
{
    public static void Main()
    {
        int[] myArray = new int[5];
        try
        {
            for (int i = 0; i < 10; i++)  // Array only has 5 elements!
           {
                myArray[i] = i;
            }
        }
        finally
        {
            Console.WriteLine("Done with exception handling");
        }
        Console.WriteLine("End of Program");
    }
}

Result


Related Tutorials