Java Basics: abnormal capture order

 Reproduced in: https://blog.csdn.net/jiyiqinlovexx/article/details/46597899

voidtestException public () {
int A [] = {l, 2,3}; int = Q 0;
the try {
for (int I = 0; I <a.length; I ++) {A [I] / = Q;}
the catch} (an ArithmeticException H) {
of System.out.print ( "an ArithmeticException \ n-"); // execute
} the catch (Exception E) {
of System.out.print ( "Exception \ n-"); // not executed, and must be placed behind ArithmeticException
/ **
 * Exception greater scope must not only be on the back
 * and on the back will not be executed (the range in front of the smaller
 * abnormal intercepted), so that there is what meaning does ? ? ?
 * /
} {The finally of System.out.print ( "the finally \ n-");}
}
// <span style = "Color: # 3333ff;"> Output </ span>
an ArithmeticException
the finally

 * Point 1: Although ArithmeticException inherited from Exception, but when an exception occurs ArithmeticException
 time * and captured, it will only catch the exception actually happened, and not because Exception class and its parent

 * Exception to perform the catch clause.

 * Point 2: But if you try to be in front of a wider range of Exception catch clause into the catch statement, it will happen

 * Catch clause error can not be reached "Unreachablecatch block for ArithmeticException.

 *                        Itis already handled by the catch block for Exception”

 * That is a wider range of abnormalities (parent) must be placed in the back, if there is no inheritance, such as ClassNotFoundException,

 It does not matter * and has the relationship between ArithmeticException catch clause.
 

Guess you like

Origin blog.csdn.net/qq_28817739/article/details/85106837