/*******************************************************************
** This application is an illustration of how the Exceptional
** handing works and it shows the throws, try, catch clauses
** plus the execution sequence of statements. The exception handling
** code can located in any of the caller.
********************************************************************/
public class ExceptionHandling_2
{
  final int   ZERO = 0;

  public ExceptionHandling_2()
  {
    int         DividByValue = 2;
    int         IntegerValue = 50;
    float       FloatValue   = -50;

    System.out.println("\n\n***  start of Constructor ExceptionHandling_2  ****");
    try
    {
      System.out.println("***  Start of the First Constructor Try Clause  ****");
      FloatValue = CallMethod_1(IntegerValue, DividByValue);
    }
    catch (ArithmeticException  MyArithmeticException)
    {
      System.out.println("*** Start of The First Constructor Catch clause  ****");
      System.out.println("***  can not divid by ZERO!!!! ****");
    }
    System.out.println("**** After the Fisrt Constructor catch clause ***********");
    System.out.println("FloatValue = \t" + FloatValue);
    System.out.println("\n====================================================\n");
    DividByValue = ZERO;
    IntegerValue = 20;
    FloatValue   = -20;
    try
    {
      System.out.println("***  Start of the 2nd Constructor Try Clause  ****");
      FloatValue = CallMethod_1(IntegerValue, DividByValue);
    }
    catch (ArithmeticException  MyArithmeticException)
    {
      System.out.println("*** Start of the 2nd Constructor Catch clause  ****");
      System.out.println("***  can not divid by ZERO!!!! ****");
    }
    System.out.println("**** After the 2nd Constructor catch clause ***********");
    System.out.println("FloatValue = \t" + FloatValue);
    System.out.println("***  End of Constructor ExceptionHandling_2  ****");
  }
  //**********************************************
  float  CatchDividByZeroMethod(int PassedInteger, int DividByInteger)
        throws ArithmeticException
  {
    System.out.println("***  The start of CatchZeroDivisionMethod   ****");
    if(0 == DividByInteger)
      throw new ArithmeticException();
    System.out.println("***  The End of CatchZeroDivisionMethod   ****");
    return (PassedInteger / DividByInteger);
  }  // CatchZeroDivisionMethod
  //**********************************************
  float Method_1(int PassedInteger, int DividByInteger)
  {
    float       FloatValue;

    System.out.println("****** start of Method_1  ************");
    FloatValue = CatchDividByZeroMethod(PassedInteger, DividByInteger);
    System.out.println("****** End of Method_1  ************");
    return(FloatValue);
  } // Method_1
  //**********************************************
  float CallMethod_1(int PassedInteger, int DividByInteger)
  {
    float       FloatValue   = -50;

    System.out.println("****** Start of CallMethod_1 ********");
    FloatValue = Method_1(PassedInteger, DividByInteger);
    System.out.println("****** End of CallMethod_1 ********");
    return(FloatValue);
  } // CallMethod_1
  /****************************************************/
  public static void main(String [] args)
  {
    ExceptionHandling_2  MyExceptionHandling_2
          = new ExceptionHandling_2();
	try
	{
		System.in.read();
	}
	catch(Exception myException)
	{// do nothing
	}
  }
}
