/*********************************************************
 * Creates five exceptions on purpose and catches them
 *
 * @author Nick Bakewell - V1 - 1/17/06
 ********************************************************/

public class Exceptions
{

	public static void main(String args[])
	{
	
		int result;
		String[] exampleArray;
		int[] intArray;
		String abc;

		
		
		abc = null;
		
		exampleArray = new String[2];
		
		exampleArray[0] = "Bob";
		exampleArray[1] = "Joe";
	
		try
		{
			// forcing an ArthimeticException by dividing by 0
			result = 14 / 0;
		}
		catch(ArithmeticException e)
		{
			System.err.println("Arithmetic Exception occurred - division by 0: " +
				e.getMessage());
		}
		
		
		try
		{
			// forcing an IndexOutOfBoundsException by calling an array value that
			// does not exist in the array
			System.out.println(exampleArray[3]);
		}
		catch(IndexOutOfBoundsException e)
		{
			System.err.println("Index Out Of Bounds Exception occurred - value exceeds " +
				"array size: " + e.getMessage());
		}
		
		
		try
		{
			// forcing a NegativeArraySizeException by attempting to create an
			// array of negative length
			intArray = new int[-3];
		}
		catch(NegativeArraySizeException e)
		{
			System.err.println("Negative Array Size Exception occurred - attempting to create " +
				"an array of negative length: " + e.getMessage());
		}
		
		
		try
		{
			// forcing a NullPointerException by referencing an object
			// that does not exist
			System.out.println(abc.length());
		}
		catch(NullPointerException e)
		{
			System.err.println("NullPointerException occurred - attempting to reference an " +
				"object that does not exist: " + e.getMessage());
		}
				
			
		
	}
	
}