Nesting Try Blocks - CSharp Custom Type

CSharp examples for Custom Type:try catch finally

Description

Nesting Try Blocks

Demo Code

using System;/*from  w  ww  . j a  va 2s.  c  o m*/
class TryNestTester
{
   public static void Main()
   {
      try
      {
         try
         {
            int[] myArray = new int[10];
            myArray[50] = 498;
         }
         catch(DivideByZeroException exObj)
         {
            Console.WriteLine("Inside inner catch block");
            Console.WriteLine("Exception: " + exObj.Message);
         }
      }
      catch(IndexOutOfRangeException exObj)
      {
         Console.WriteLine("Inside outer catch block");
         Console.WriteLine("Exception: " + exObj.Message);
      }
   }
}

Result


Related Tutorials