import java.io.*; //Imports the IOException class...


public class ExceptionTests
{
	public ExceptionTests() {}


	public void doSomeIO() throws IOException
	{
		//Assume some error occurred...
		//Normally, this should only happen
		//if a real error occurs but for
		//testing we will just throw an IOException!
		throw new IOException("While reading a file, an error occurred!");
	}

	public static void main(String[] args)
	{
		ExceptionTests tester=new ExceptionTests();

		try
		{
			System.out.print("\n\n>>> I'm at the start of the TRY block!\n\n");
			
			//Comment the next line out
			//to skip the exception from being thrown
			//and see what happens when we reach the end
			//of the try block.
			//We will skip the catch block
			//and continue on to the finally block.
			//Remember to recompile!
			tester.doSomeIO();

			System.out.print("\n\n>>> I'm at the end of the TRY block!\n\n");
		} //End Try Block
		catch(IOException e)
		{
			System.out.print("\n\n>>> I'm in the CATCH block!\n\n");

			//This is something we normally
			//want to do at the top level of
			//our code to "log" the error to STDERR.
			//You can printStackTrace any where in the
			//code you want, but definitely always
			//print it at the entry point to the code,
			//so you will always log all errors.
			//This assumes you throw your exceptions
			//ALL the way up the call stack.
			e.printStackTrace();
		}
		finally
		{
			System.out.print("\n\n>>> I'm in the FINALLY block!\n\n");
		}
	}
}
