Using Multiple catches for a Single try - CSharp Custom Type

CSharp examples for Custom Type:try catch finally

Description

Using Multiple catches for a Single try

Demo Code

using System;/*from   w w w . j av a2  s  .c  om*/
class CatchIndex
{
   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;
         }
      }
      catch (IndexOutOfRangeException e)
      {
         Console.WriteLine(  "You were very goofy trying to use a bad array index!!", e);
      }
      catch (Exception e)
      {
         Console.WriteLine("Exception caught: {0}", e);
      }
      Console.WriteLine("\nDone with the catch statements. Done with program.");
   }
}

Result


Related Tutorials