1. Exceptions in the program
(1) in the process of running the program, the accident occurred, deviation from the intention of our program itself, can be understood as abnormal.
(2) Using the exception mechanism in Java, we can improve the robustness of the program.
(3) in Java, a variety of different exception types are described by Throwable and their subclasses.
2. Type of exception
3. Exception Handling
In Java applications, the exception handling mechanism is: Throw an exception, catch an exception
Implemented with 5 keywords: try, catch, finally, throw, throws
4.try-catch-finally
Experience and summary in practical application
(1) When handling the abnormal operation, the logic is used to avoid the auxiliary try-catch processing.
(2) After multiple catch fast, you can add a catch (Exception) to handle the exceptions that may be missed.
(3) For uncertain code, you can also add try-catch to deal with potential anomalies.
(4) Try to handle the exception, avoid simply call Printstacktrace () to print output
(5) How to deal with the exception, according to different business needs and the type of exception to decide
(6) Try to add the finally statement to release the resources that are occupied
5.throw, throws
You can declare the type of exception that will be thrown through the throws and throw the resulting exception by throw
If a method may have an exception, but is incapable of handling the exception, you can throw an exception with the throws clause at the method declaration
6.throw Rules of Use
When a subclass overrides a method that the parent class throws an exception, the declared exception must be the same class or subclass of the exception declared by the parent class method
7.throws Rules of Use
When a subclass overrides a method that the parent class throws an exception, the declared exception must be the same class or subclass of the exception declared by the parent class method
8. Custom Exceptions
Custom exceptions can be used to describe the types of exceptions generated by a particular business
The so-called custom exception, is to define a class, to inherit the Throwable class fire its subclass
9. Abnormal chain
When you catch an exception and throw another exception, if you want to send the cause of the exception to a string, that is, the underlying exception information to the upper layer, it formed an abnormal chain