/*
   This program shows how try\catch clauses can be used to make a
   program handle errors in a more gracefull way than just crashing.
*/

public class CauseExceptionsAndCatchThem2c
{
   public static void main(String[] args)
   {
      boolean done = false;
      while(!done)
      {
         try
         {
            System.out.print("Either enter a misformed integer or 0: ");
            int a = MyInput.readInt();       // this can cause a number format exception
            System.out.println(1/a); // this can cause an arithmetic exception

            System.out.println("\nOur try clause terminates normally.\n");
            done = true;
         }
         catch(NumberFormatException e) // this catches the number format exception
         {
            System.out.println("Good job. Now try entering 0.");
         }
         catch(ArithmeticException e) // this catches the arithmetic exception
         {
             System.out.println("Good job. Now try entering an improper integer.");
         }
      }

      System.out.println("\nOur program terminates normally.\n");
   }//main

}//CauseExceptionsAndCatchThem2c