文档
A try
statement with a finally
block is executed by first executing the try
block. Then there is a choice:
-
If execution of the
try
block completes normally, then thefinally
block is executed, and then there is a choice:-
If the
finally
block completes normally, then thetry
statement completes normally. -
If the
finally
block completes abruptly for reasonS
, then thetry
statement completes abruptly for reasonS
.
-
-
If execution of the
try
block completes abruptly because of athrow
of a valueV
, then there is a choice:-
If the run-time type of
V
is assignment compatible with a catchable exception class of anycatch
clause of thetry
statement, then the first (leftmost) suchcatch
clause is selected. The valueV
is assigned to the parameter of the selectedcatch
clause, and the Block of thatcatch
clause is executed. Then there is a choice:-
If the
catch
block completes normally, then thefinally
block is executed. Then there is a choice:-
If the
finally
block completes normally, then thetry
statement completes normally. -
If the
finally
block completes abruptly for any reason, then thetry
statement completes abruptly for the same reason.
-
-
If the
catch
block completes abruptly for reasonR
, then thefinally
block is executed. Then there is a choice:-
If the
finally
block completes normally, then thetry
statement completes abruptly for reasonR
. -
If the
finally
block completes abruptly for reasonS
, then thetry
statement completes abruptly for reasonS
(and reasonR
is discarded).
-
-
-
If the run-time type of
V
is not assignment compatible with a catchable exception class of anycatch
clause of thetry
statement, then thefinally
block is executed. Then there is a choice:-
If the
finally
block completes normally, then thetry
statement completes abruptly because of athrow
of the valueV
. -
If the
finally
block completes abruptly for reasonS
, then thetry
statement completes abruptly for reasonS
(and thethrow
of valueV
is discarded and forgotten).
-
-
-
If execution of the
try
block completes abruptly for any other reasonR
, then thefinally
block is executed, and then there is a choice:-
If the
finally
block completes normally, then thetry
statement completes abruptly for reasonR
. -
If the
finally
block completes abruptly for reasonS
, then thetry
statement completes abruptly for reasonS
(and reasonR
is discarded).
-
网友评论