//
// ExceptionTest.java
// Demonstrates exception handling in Java
//
// Nadeem Abdul Hamid
// CSC 121 - Berry College
//

import java.io.*;


class IllegalArgumentException extends Exception
{
    public IllegalArgumentException( String msg ) 
    {
	super( msg );
    }
}


public class ExceptionTest2
{
    public static int quotient( int num, int denom ) 
	throws IllegalArgumentException
    {
	if ( denom == 0 ) 
	    throw new IllegalArgumentException( "Cannot call quotient() with 0 denominator." );
	return num / denom;
    }


    public static void main( String args[] ) 
    {
	System.out.println( "Welcome!" );

	boolean continueloop = true;  // loop will continue until valid input

	BufferedReader in             // keyboard input object
	    = new BufferedReader( new InputStreamReader( System.in ) );

	do 
        {
	    try {
		String n = in.readLine();
		String d = in.readLine();
		System.out.println( n + "/" + d );
		System.out.println( quotient( Integer.parseInt( n ), 
					      Integer.parseInt( d ) ) );
		System.out.println( "Thank you!" );
		continueloop = false;    // processing successful, stop loop
	    } // end try
	    catch ( IllegalArgumentException e ) {
		System.out.println( e );
	    } // end catch IllegalArgumentException
	    catch ( NumberFormatException e ) {
		System.out.println( "Format error: please type integers." );
		e.printStackTrace();
	    } // end catch NumberFormatException
	    catch ( IOException e ) {
		System.out.println( "IO exception occurred: " + e );
	    } // end catch IOException
	    finally {
		System.out.println( "This executes no matter what." );
		// e.g. close open files, etc.
	    } // end finally
	} while ( continueloop );

	System.out.println( "Good bye!" );
	
    }
}