--- Exception handling abnormal

There are two kinds of abnormal Exception error in the error code programming, they are inherited from Throwable --- is the root class, the only instance of Throwable in Java types can be thrown (throw) or capture (catch) in which the error error is a Java program running in unexpected exceptions, this situation can not solve the problem with the code, this error is often the problem is hardware or operational problems. Therefore, this exception is not possible to fetch such OutOfMemoryError, NoClassDefFoundError like.

The main problem I encountered in writing code or Exception .. Abnormal event, the JVM depending on the type of abnormality occurs, the exception generating objects, the object is then processed to the code, if not treated, this method will end abnormality occurs, with the method that called method returns to see if there is no treatment just not back up, layer by layer until processed. If you have not then return to the main method, the JVM will end the program and prints an error. The Exception divided into two categories, one is a compile-time anomaly, the other is abnormal RuntimeException / uncheckException runtime, you can ignore the capture operation

Usually use try ... catch ... finally you may use try ... catch, try ... finally, or not using the finally try; try block generally normal writing logic code abnormality may occur, the test run, such as estimated that there is no error, the order would have been run, if error, it would stop running the current code, jump to capture good (catch {}). Wherein finally the exception generally used in the capture, will perform the final, generally used to close the stream or a database connection. If used in the try block represents the return ends, the first return data, the data can not be performed finally try to overwrite the data block. A plurality of abnormality may be abnormal, then it can be handled in different exceptions try block followed by a plurality of catch blocks, it is to be noted that the order of the caught exception will be captured on the front subclass, placed behind the capture parent class, will finally put in the final, finally refers to the code will be executed regardless of whether an exception occurs, either break or return can not stop his execution, that can stop him only System.exit (0);

It is finally executed before the return of this action, and in return after preparation.

 

 

 

Guess you like

Origin www.cnblogs.com/wanggang1987/p/11971554.html