/**
 * TestException4.java -- this is an application that illustrates the use of
 * try-catch handling (exception handling) to show how an exception can be
 * thrown, caught, and propagated.  This is based on Thomas Wu's example.
 * This is to show how a runtime exception can be propagated.  
 *
 * CSCE 155 Fall 2005
 * @author Leen-Kiat Soh
 * @version 1.0
 */

class TestException4 { 

   private String arg;

   /**
    * This is the construtor that initializes two member values: cond, and arg.
    * It takes two arguments, an integer and a string.
    * @param what a String set to arg.
    */

   public TestException4(String what)  {

      arg = what;

   }  // end constructor


   /**
    * This is a method that calls B.  Is this method an exception thrower?
    */

   public void A()  {

      try {
         B();
      }  catch (Exception e)  {
         System.out.println("A");
      }

   }  // end A
   
   /**
    * This is a method that calls C.  This is an exception thrower, as well as
    * a catcher.
    */

   public void B()  {

      try {
         C();
      }  catch (Exception e)  {
         System.out.println("B");
      }
   }  // end B

   /**
    * This is a method that calls D.  This is an exception thrower, as well as
    * a propagator.  Why is it necessary to include "throws Exception"?
    */

   public void C() throws Exception {

      D();

   }  // end C

   /**
    * This is a method that throws an exception if cond is true.  It is a
    * thrower and a propagator.
    * Why is it necessary to include "throws Exception"?
    * If I replace the 'if' statement with the "int choice =
    * Integer.parseInt(arg)" statement, do I still need to explicitly declare
    * "throws Exception"?  Why? or Why not?
    */

   public void D() throws Exception {

      int choice = Integer.parseInt(arg);
       
   }  // end D
     
   public static void main(String[] args)  {

      TestException4 te4 = new TestException4(args[0]);
      te4.A();

   }  // end main

}  // end TestException4 class

