Java Exception
since May 11, 2000, last modified May 11, 2000
1. Concept and Terminalogy
- Exception: Exceptional Events
- Exception object: An object which has exception information
- Throwing an exception: Creating an Exception Object and handling it to runtime system (by the method in which the error occurred)
- A Mehtod which has exception handler: A method (in the call stack of the method throwing an exception) which handls sametype of the exception occurred.
- Catch the exception: The method which handle the exception (see "A Method which has exception handler")
2. How to define
- If called method has 'throwing exception', a caller method in the call stack should have 'catching excetpion' routine (see the following example, the navi() caller and canvas() called in navi calss)
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