Java exception Mechanism
Java exception Mechanism
I have nothing to do after work. Let's take a look at the basic java knowledge and make a summary.
Exception mechanism: a control process solution provided by java to solve emergencies or misoperations
Throwable all errors or exceptional superclasses, including two subclasses: Error and Exection
The Error is not handled by the program, such as memory overflow or machine power failure.
Exception exceptions include runtime exceptions and compilation exceptions.
Runtime exception classes all inherit RuntimeException, common such as NullPointerException, ArithmeticException, IndexOutOfBoundsException, etc.
Compilation exception, non-runtime exception, must be processed during compilation, such as IOException (subclass such as FileNotFoundException)
Exception Handling:
1) try {
// Action to be executed by the program
} Catch (Arthur meticexception e ){
// Actions that the program may execute
E. printStackTrace ();
} Catch (Exception e ){
// Actions that the program may execute
} Finally {
// The action that the program will execute
}
Tip: You can use return to learn more about try catch.
Note: When multi-layer catch occurs, the exception class range is large.
2) throws and throw
Throws declares an exception.
Throw throws an exception object.
Note: An exception is thrown when an exception is declared. If the caller does not handle the exception, the caller will continue to throw the exception.
Custom exception:
You can customize your own Exception classes as needed, and normally define the Exception classes that inherit exceptions.
To be continued ....