java exception Exception and common RunTimeException

java exception Exception and common RunTimeException

All exceptions are inherited from Throwable and are broken down into two branches at the next level: Error and Exception.

The Error class hierarchy describes internal errors and resource exhaustion errors of the Java runtime system. The application should not throw objects of this type. If such an internal error occurs, in addition to notifying the user and trying to make the program terminate safely, there is nothing else that can be done. This situation rarely occurs.

When designing a Java program, you need to pay attention to the exception information of the Exception layer:
this hierarchy is divided into two branches: RunTimeException and Exception:

1. Exceptions caused by program errors belong to RuntimeException , that is, runtime exceptions, which are also called unchecked exceptions. The compiler does not report errors. When such exceptions occur, they are directly handed over to the virtual machine. Common exceptions
derived from RuntimeException include the following situations:

NullPointerException-Null pointer reference exception
ClassCastException-Type cast exception.
IndexOutOfBoundsException-Subscript out-of-bounds exception
FileNotFoundException-File not found exception
ArithmeticException-Arithmetic operation exception
IllegalArgumentException-Passing illegal parameter exception.
NegativeArraySizeException-Create an array with a negative size error
NumberFormatException-Number format exception
SecurityException-Security exception
UnsupportedOperationException-Unsupported operation exception

"If there is a RuntimeException, it must be your problem", this sentence still makes sense

2. Other exceptions, also known as checked exceptions, will expose errors at compile time. You need to catch and handle exceptions that
are not derived from RuntimeException including:
trying to read data after the end of the file.
Trying to open a file that does not exist.
Try to find the Class object based on the given string , and the class represented by this string does not exist

Published 60 original articles · 25 praises · 10,000+ views

Guess you like

Origin blog.csdn.net/qq_41466437/article/details/105490971