Java learning notes -- exceptions, Java learning notes --
The Throwable Java class is used to indicate any classes that can be thrown as exceptions. Throwable objects can be divided into two types (derived from Throwable inheritance ):
Error:Used to indicate Compilation Time and system errors (generally do not care)
Exception:Is the basic type that can be thrown. Exception type exceptions may be thrown in Java class libraries, user methods, and runtime faults. Therefore, we need to care about this.
If an Exception occurs, we must capture or throw it.
There is a special case:RuntimeException
It is very troublesome to check all input references as follows.
If (t = null) throw new NullPointerException ();
Therefore, some exceptions (runtime exceptions) do not need to be detected. They are automatically detected and thrown out. If we do not capture it, The RuntimeException exception will go through all the execution paths to the main () method, and call the abnormal printStackTrace () method before the program exits.
In case of a common exception, the exception must be caught or thrown using the throws Declaration on the method in which it is located. In case of a runtime exception, the exception can not be captured, you do not need to declare the thrown exception in the method.