Exception handling
1.try...catch Catching exceptions
The curly brackets of the try and catch blocks cannot be omitted
Catch a small exception when catching an exception, and then catch a large exception
Java7 start a catch block to catch multiple exceptions, multiple exceptions "|" Separate
Access exception information
2. Use finally to reclaim resources
Garbage collection in Java only reclaims resources consumed by objects in heap memory, and physical resources need to be explicitly recycled
Finally blocks are always executed (unless the SYSTEM.EXIT (1) statement is called to exit the virtual machine)
Finally, try not to use return or throw and other statements that lead to the termination of the method (because the return statement in the Try,,,catch,,,,, is not executed immediately after the call, but first to execute the FINALLY statement, executed and then back to try to execute, if, After a return is called in the Finall, the try is no longer executed)
3. Exception Handling Nesting
4. A try statement (JAVA7) that automatically closes a resource
Try the parentheses to achieve resource closure, to ensure that resources are closed, this resource must implement the Autocloseable or Closeable interface, the implementation of both interfaces, must be close ()
5.Checked anomaly and runtime anomaly system
Checked exceptions must be handled explicitly, with catch or throws
6. Throwing Exceptions using throws
7. Throw with throw: throws an exception by itself, only throws an instance
8. Custom exception class: Inherit exception or RuntimeException
9. Throw the exception again with throw in catch
10. Abnormal chain
Exception tracking stack for 11.Java
12. Exception Handling Rules
Java Exception Handling