/*
   Besides a main() method, this program has two other static methods,
   methodA() and methodB(). The main() method calls methodA(), and methodA()
   calls methodB(). methodB() can cause two different kinds of exceptions.
   Both kinds of exception are uncaught, and so they cause the program to
   immediately terminate.

   Each method, methodB(), methodA(), and the main() method, "throws" the
   uncaught exceptions to the method that called it, to see if the calling
   method might have an exception handler in it.
*/
import jpb.*;

public class CauseExceptions3
{
   public static void main(String[] args)
   {
      methodA();

      System.out.println("\nOur program terminates normally.\n");
   }//main

   public static void methodA() //throws NumberFormatException, ArithmeticException
   {
      methodB();

      System.out.println("\nMethodA terminates normally.\n");
   }//methodA

   public static void methodB() //throws NumberFormatException, ArithmeticException
   {
      System.out.print("Either enter a misformed integer or 0: ");
      String userInput = SimpleIO.readLine();
      int a = Integer.parseInt(userInput); // this can cause a number format exception
      System.out.println(1/a);    // this can cause an arithmetic exception

      System.out.println("\nMethodB terminates normally.\n");
   }//methodB

}//CauseExceptions3