The system of anomalies
Throwable
|--error Serious problems
|--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
Try...catch...finally
try{
Problem codes that may occur
}catch (Exception name variable) {/////According to the new feature after JDK7 we can add multiple variable exception names (exceptions must be between siblings) when processing
How to Handle
}finally{
Freeing resources
}
Throws
You can't handle it, or you don't have permission to handle it, declare it on the method, tell the caller, there's a problem.
Throw an exception directly behind the class
It is important to note that the exception thrown after the method, if it is a compile-time exception, we call this method must always be resolved, if the runtime of the exception we can not control it.
The difference between throw and throws
Throw
In the method body, followed by the exception object name, and can only be a
Throw throws an exception object, which means there must be an exception here.
Throws
On the method declaration, followed by the class name of the exception, can be multiple
Throws is a method of declaring an exception, which is a possibility, and this exception does not necessarily produce
Finally
Finally is used to free up resources, and its code is always executed. Special case: The JVM exited before executing to finally
Java Learning Day 19th (exception)