Catching Exception Information - CSharp Custom Type

CSharp examples for Custom Type:Exception

Description

Catching Exception Information

Demo Code

using System;// w  w w. ja  v  a 2 s . c o m
class TryIt2
{
   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( Exception e)
      {
         Console.WriteLine("The following exception was caught:\n{0}", e);
      }
      Console.WriteLine("At end of class");
   }
}

Result


Related Tutorials