p270~p272
1, create the exception class.
Step: 1) Define a class that derives from (inherits) exception or its subclasses.
2) Add two construction methods: one is the default constructor and the other is a constructor with a detailed description of the information.
import java.io.IOException; /* */Publicclass myexception extends ioexception{public myexception () {} Public myexception (String gripe) { super (gripe); }}
additions: Inheritance in the constructor method (do not write the default has an implicit construction method)
2, catch the exception.
To catch an exception, you must set the Try/catch statement block. Examples are as follows:
Try { // code // more code catch (exceptiontype e) { // handlerfor this Exception}
If any code in the try statement block throws an exception that is described in the catch clause,
1) The program skips the remaining code of the try statement block. 2) Execute the processor code in the catch.
Core Java 3