Anomaly Classification Plots:
Throwable
|--error serious problems that we do not deal with.
|--exception
|--runtimeexception run-time exception, we need to fix the code
|--non-RuntimeException compile-time exception, must be handled, or program compilation does not pass
Common methods for exception objects:
If a program needs to access information about an object in a catch block, it can be obtained by accessing the exception parameter after the catch block. When the Java runtime decides to call a catch block to process the exception object, it assigns the exception object to the exception parameter after the catch block, which the program can use to obtain information about the exception.
GetMessage (): Returns the detailed description string for the exception
Printstacktrace (): Outputs the trace stack information for this exception to the standard error output.
Printstacktrace (PrintStream s): Outputs the trace stack information for this exception to the standard error output.
Getstacktrace (): Returns the trace stack information for this exception.
The special case of finally:
In general, do not use a statement such as return or throw that causes a method to terminate in a finally block.
When a Java program executes a try block, a catch block, it encounters a return or throw statement. Both statements cause the method to end immediately, but the system executes the two statements and does not end the method, but instead finds out whether the exception process contains a finally block, and if there is no finally block, the program executes the return or throw statement immediately, terminating the method. If there is a finally block, the system immediately begins execution of the finaly block----The system will not jump back to execute the try block, the Retrun in the catch block, or the throw statement until the finally block finishes executing If the finally block also uses a return or throw and other statements that cause the method to terminate, the finally block one catty terminates the method, the system will not jump back to execute any code in the try block, catch block.
Custom exceptions
Inherited from exception or runtimeexception, it is only necessary to provide a non-parametric construction and a parameter structure.
Java Fundamentals (10)---exceptions