(1) basic concepts
The abnormal structure of Java
Throwable is the root of all exceptions, java.lang.Throwable
Error is wrong, java.lang.Error
Exception is an exception, java.lang.Exception
Generally divided into Checked exceptions and Runtime exceptions, all instances of the RuntimeException class and its subclasses are called Runtime exceptions, and exceptions that are not in that category are called CheckedException.
Only the Java language provides Checked exceptions, and Java considers that Checked exceptions are exceptions that can be processed, so the Java program must display the handling of the Checked exception. If the program does not handle the Checked exception, the program will compile errors and cannot compile. This reflects Java’s philosophy of design: code without perfect error handling does not have the chance to be executed at all. There are two kinds of Checked exception handling methods:
The A. current method knows how to handle this exception, and uses the try / catch block to handle the exception. The
B. does not know how to handle the current method, and declares that exception is thrown when the method is defined.
We are more familiar with Checked abnormalities
Java.lang.ClassNotFoundException Java.lang.NoSuchMetodException java.io.IOException
Runtime such as the divisor is 0 and the array subscript is out of bounds, and so on, it produces frequently, handles the trouble, if displays the declaration or captures, will affect to the procedure readability and the operation efficiency very big. So they are automatically detected by the system and handed over to the default exception handler. Of course, if you have processing requirements, you can also display capture them.
We are more familiar with Subclasses of the RumtimeException class
Java.lang.ArithmeticException, Java.lang.ArrayStoreExcetpion, Java.lang.ClassCastException, Java.lang.IndexOutOfBoundsException, Java.lang.NullPointerException
When an uncontrollable error occurs in a program, the usual practice is to notify the user and abort the execution of the program. Unlike exceptions, objects of Error and its subclasses should not be thrown.
Error is a subclass of throwable that represents compilation errors and system errors that are used to indicate a serious problem that a reasonable application should not attempt to capture.
Error is generated and thrown by the Java virtual machine, including dynamic link failure, virtual machine error, and so on. The program does not handle it.