Java Exception
since May 11, 2000, last modified May 11, 2000

1. Concept and Terminalogy

2. How to define

An Example of Java Exception

/* Caller: catch exception
=========================*/
class navi
	{
	...
	public navi() /* navi constructor  */
		{
		try
			{
			canvas1 = new canvas(); /* navi() is the new canvas() Caller */
			}
		catch (IOException e) /* CATCH EXCEPTION */
			{
			System.err.println("CheckedIOTest: " + e);
			System.exit(-1);
			}
		}
	}

	/* Called: throw exception
	=========================*/
class canvas
	{
	...
	public canvas() throws IOException 
	/* canvas constructor - 
	THROW EXCEPTION to caller, new navi() method */
		{
		try {
		in = new FileReader("input.txt");
		out = new FileWriter("output.txt");
		} 
		catch (FileNotFoundException e) /* CATCH EXCEPTION, Is it needed ? */
			{
			System.err.println("CheckedIOTest: " + e);
			System.exit(-1);
			} 
		catch (IOException e) 
			{
			System.err.println("CheckedIOTest: " + e);
			System.exit(-1);
			}
		}
	}

For more information of Java Exception, see The Java Tutorial "Essential Java Classes.Handling Errors with Exceptions" section.



Knowledge and Engineering Databases (c) copyright Namchul Do, 2000