/*
   This program causes a number of different kinds of exceptions
   but it catches every one of the exceptions that it causes.
   So the program is able to continue executing after each
   one of the exceptions is handled.
*/

public class CauseExceptionsAndCatchThem1a
{
   public static void main(String[] args)
   {
      int[] myArray = new int[5];
      try
      {
         myArray[5] = 0;  // array index out of bounds excption
      }
      catch(ArrayIndexOutOfBoundsException e)
      {
         System.out.println("Opps! We have a: " + e);
      }

      String myString = null;
      try
      {
         myString.toUpperCase();  // null pointer exception
      }
      catch(NullPointerException e)
      {
         System.out.println("Opps! We have a: " + e);
      }

      int a = 1;
      int b = 0;
      try
      {
         System.out.println( a/b );  // arithmetic exception
      }
      catch(ArithmeticException e)
      {
         System.out.println("Opps! We have a: " + e);
      }

      try
      {
         Integer.parseInt("1o2"); // number format exception
      }
      catch(NumberFormatException e)
      {
         System.out.println("Opps! We have a: " + e);
      }


      System.out.println("\nOur program terminates normally.\n");
   }//main

}//CauseExceptionsAndCatchThem1a