First, Introduction
According to the JDK documentation we can find the package where the exception is: Java.lang.Throwable, Throwable is the root class of all exception classes, error is wrong in Java.lang.error, and exception is abnormal in java.lang.exception can be found in
II. Overview of the error
When error class errors occur, the reason we need to associate this error is that most of the problems are related to virtual machines, such as insufficient memory, virtual machine errors, and so on. For these error messages to cause a program outage to stop, this behavior can only be repaired by modifying the code itself, and more advice is to terminate the program.
Iii. Overview of exception
When exception occurs, the program itself can handle the exception itself, which is the difference from the nature of the error, which cannot be handled by itself when an error occurs.
Exception has a lot of subclasses, so viewing the JDK documentation can draw exception exceptions and can be divided into Runntime exception and other exceptions:
- RuntimeException exception occurs, it must be written code problems, such as the array out of bounds are not considered, NULL pointer exception does not take into account such information, so do not need to pass the throws processing, can be thrown directly, thrown to do not require the caller to handle, The caller can either handle it or not, and if it does not, it will be thrown up and then thrown to the virtual machine to stop the current thread.
- When other exceptions occur, we can capture this exception (Try-catch) or throw the exception (throws) in the execution code, so once thrown, the caller must handle
Common Types of exceptions:
ArrayIndexOutOfBoundsException array Subscript out-of-bounds exception,
ClassNotFoundException type does not exist
NullPointerException NULL pointer exception
IllegalArgumentException Illegal parameter exception
What are the exception types and differences in Java?????