//TestExceptions.java
//Do some questionable things just to see what exception is thrown ...

import java.util.Scanner;

public class TestExceptions
{
    public static void main(String[] args)
    {
        try
        {
            //Activate the lines below one at at time
            //System.out.println(5/0); //ArithmeticException
            //System.out.println(args[5]); //ArrayIndexOutOfBoundsException
            System.out.println(Math.sqrt(-1)); //Actually we get NaN
        }
        catch (ArithmeticException e)
        {
            System.out.println("Sorry ... can't do that!");
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
            System.out.println("Sorry ... can't do that either!");
        }
        catch (Exception e)
        {
            System.out.println("Who knows what happened ... ?");
        }
    }
}

/*
 * Note that the exceptions above are runtime exceptions, and as such are
 * unchecked and do not need to be explicitly dealt with by the programmer.
 */

