Write a program in java to demonstrate exception handling with multiple try block?

class MultipleTryBlock

{

      public static void main(String arg[])

      {

            try

            {

                  System.out.println("Hii");

                  try

                  {

                        System.out.println("Going To Divide");

                        System.out.println(4/0);

                  }

                  catch(ArithmeticException e)

                  {

                        System.out.println("Divide Error");

                  }

                  try

                  {

                        int a[]=new int[5];

                        a[5]=7;

                  }

                  catch(ArrayIndexOutOfBoundsException e)

                  {

                        System.out.println("Range Out");

                  }

            }

            catch(Exception e)

            {

                  System.out.println("Handled");

            }

            System.out.println("Finished");

      }

}

Exception Handling Multiple Try Block.PNG

, , , , , , , ,

Leave a Reply