/*******************************************************************
** 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.
********************************************************************/
public class ExceptionHandling_1
{
  final int   ZERO = 0;

  public ExceptionHandling_1()
  {
    Method_1();
    System.out.println("===========================================");
    Method_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
  //**********************************************
  void Method_1()
  {
    int         DividByValue = ZERO;
    int         IntegerValue = 20;
    float       FloatValue   = -20;

    System.out.println("***  The Start of Method_1   ****");
    System.out.println("FloatValue = \t" + FloatValue);
    try
    {
      System.out.println("***  Start of Method_1 Try Clause  ****");
      FloatValue = CatchDividByZeroMethod(IntegerValue, DividByValue);
    }
    catch (ArithmeticException  MyArithmeticException)
    {
      System.out.println("*** Start of Method_1 Catch clause  ****");
      System.out.println("***  can not divid by ZERO!!!! ****");
      String ErrorMessage = MyArithmeticException.getMessage();
      System.out.println("ErrorMessage = " + ErrorMessage);
      MyArithmeticException.printStackTrace();
//      return;
    }
    System.out.println("FloatValue = \t" + FloatValue);
    System.out.println("***  The End of Method_1   ****");
  } // Method_1
  //**********************************************
  void Method_2()
  {
    int         DividByValue = 2;
    int         IntegerValue = 50;
    float       FloatValue   = -50;

    System.out.println("***  The Start of Method_2   ****");
    System.out.println("FloatValue = \t" + FloatValue);
    try
    {
      System.out.println("***  Start of Method_2 Try Clause  ****");
      FloatValue = CatchDividByZeroMethod(IntegerValue, DividByValue);
    }
    catch (ArithmeticException  MyArithmeticException)
    {
      System.out.println("*** Start of Method_2 Catch clause  ****");
      System.out.println("***  can not divid by ZERO!!!! ****");
      String ErrorMessage = MyArithmeticException.getMessage();
      System.out.println("ErrorMessage = " + ErrorMessage);
      MyArithmeticException.printStackTrace();
//      return;
    }
    System.out.println("FloatValue = \t" + FloatValue);
    System.out.println("***  The End of Method_2   ****");
  } // Method_2
  /****************************************************/
  public static void main(String [] args)
  {
    ExceptionHandling_1  MyExceptionHandling_1
          = new ExceptionHandling_1();
	try
	{
		System.in.read();
	}
	catch(Exception myException)
	{// do nothing
	}
  }
}
