/*******************************************************************
** This application is an illustration of Multiple Exceptions
********************************************************************/
import java.io.*;
import java.lang.*;


public class MultipleExceptions
{
  final int   ZERO = 0;
  int         ExecutionCount = 0;

  public MultipleExceptions()
  {
    Method_1(10);
    promptForCarriageReturn();
    System.out.println("===========================================");
    Method_1(2);
    promptForCarriageReturn();
    System.out.println("===========================================");
    Method_1(1);
    promptForCarriageReturn();
    System.out.println("===========================================");
    Method_1(0);
  }
  //**********************************************
  float  MultiExceptionMethod(int PassedInteger)
        throws ArithmeticException,
               IOException,
               IndexOutOfBoundsException
  {
    ExecutionCount++;
    System.out.println(ExecutionCount
                  + ")***  The start of MultiExceptionMethod   ****");
    if(0 == PassedInteger)
      throw new ArithmeticException();
    else
      if(1 == PassedInteger)
        throw new IOException();
      else
        if(2 == PassedInteger)
          throw new IndexOutOfBoundsException();
    ExecutionCount++;
    System.out.println(ExecutionCount
                  + ")***  End of MultiExceptionMethod ****");
    return (PassedInteger);
  }  // MultiExceptionMethod
  //**********************************************
  void Method_1(int IntegerValue)
  {
    float       FloatValue   = -20;

    ExecutionCount++;
    System.out.println(ExecutionCount
                  + ")***  The start of Method_1   ****");
    ExecutionCount++;
    System.out.println(ExecutionCount
                  + ")FloatValue = \t" + FloatValue);
    try
    {
      ExecutionCount++;
      System.out.println(ExecutionCount
                  + ")***  Start of Method_1 Try Clause  ****");
      FloatValue = MultiExceptionMethod(IntegerValue);
    }
    catch (ArithmeticException  MyArithmeticException)
    {
      ExecutionCount++;
      System.out.println(ExecutionCount
                  + ")*** Start of ArithmeticException catch Clause  ****");
    }
    catch (IOException  MyIOException)
    {
      ExecutionCount++;
      System.out.println(ExecutionCount
                  + ")*** Start of IOException catch Clause  ****");
    }
    catch (IndexOutOfBoundsException  MyIndexOutOfBoundsException)
    {
      ExecutionCount++;
      System.out.println(ExecutionCount
                  + ")*** Start of IndexOutOfBoundsException catch Clause  ****");
    }
    finally
    {
      ExecutionCount++;
      System.out.println(ExecutionCount
                  + ")*** Start of Method_1 finally clause  ****");
    }
    ExecutionCount++;
    System.out.println(ExecutionCount
                  + "**** After Method_1 finally Block *****");
    ExecutionCount++;
    System.out.println(ExecutionCount
                  + ")FloatValue = \t" + FloatValue);
    ExecutionCount++;
    System.out.println(ExecutionCount
                  + ")***  The End of Method_1   ****");
  } // Method_1
  /****************************************************/
  void promptForCarriageReturn()
  {
	System.out.println("Press Enter key to continue");
	try
	{
		int readKey = System.in.read();
		if(   ('\r' == readKey)
		   || ('\n' == readKey)
		  )
		 System.in.read();
	}
	catch(Exception myException)
	{// do nothing
	}
  }
  /****************************************************/
  public static void main(String [] args)
  {
    MultipleExceptions  MyMultipleExceptions
          = new MultipleExceptions();
	try
	{
		System.in.read();
	}
	catch(Exception myException)
	{// do nothing
	}
  }
}
