文档
A try statement with a finally block is executed by first executing the try block. Then there is a choice:
-
If execution of the
tryblock completes normally, then thefinallyblock is executed, and then there is a choice:-
If the
finallyblock completes normally, then thetrystatement completes normally. -
If the
finallyblock completes abruptly for reasonS, then thetrystatement completes abruptly for reasonS.
-
-
If execution of the
tryblock completes abruptly because of athrowof a valueV, then there is a choice:-
If the run-time type of
Vis assignment compatible with a catchable exception class of anycatchclause of thetrystatement, then the first (leftmost) suchcatchclause is selected. The valueVis assigned to the parameter of the selectedcatchclause, and the Block of thatcatchclause is executed. Then there is a choice:-
If the
catchblock completes normally, then thefinallyblock is executed. Then there is a choice:-
If the
finallyblock completes normally, then thetrystatement completes normally. -
If the
finallyblock completes abruptly for any reason, then thetrystatement completes abruptly for the same reason.
-
-
If the
catchblock completes abruptly for reasonR, then thefinallyblock is executed. Then there is a choice:-
If the
finallyblock completes normally, then thetrystatement completes abruptly for reasonR. -
If the
finallyblock completes abruptly for reasonS, then thetrystatement completes abruptly for reasonS(and reasonRis discarded).
-
-
-
If the run-time type of
Vis not assignment compatible with a catchable exception class of anycatchclause of thetrystatement, then thefinallyblock is executed. Then there is a choice:-
If the
finallyblock completes normally, then thetrystatement completes abruptly because of athrowof the valueV. -
If the
finallyblock completes abruptly for reasonS, then thetrystatement completes abruptly for reasonS(and thethrowof valueVis discarded and forgotten).
-
-
-
If execution of the
tryblock completes abruptly for any other reasonR, then thefinallyblock is executed, and then there is a choice:-
If the
finallyblock completes normally, then thetrystatement completes abruptly for reasonR. -
If the
finallyblock completes abruptly for reasonS, then thetrystatement completes abruptly for reasonS(and reasonRis discarded).
-
流程图
try-catch-finally执行流程图.png












网友评论