The rules herein cover the try-catch and try-catch-finally statements (§14.20.1, §14.20.2). Since the try-with-resources statement (§14.20.3) is defined by translation to a try-catch-finally statement, no special rules need to be provided for it.
These rules apply to every try statement (§14.20), whether or not it has a finally block:
-
V is [un]assigned before the
tryblock iff V is [un]assigned before thetrystatement. -
V is definitely assigned before a
catchblock iff V is definitely assigned before thetryblock. -
V is definitely unassigned before a
catchblock iff all of the following are true:- V is definitely unassigned after the
tryblock. - V is definitely unassigned before every
returnstatement that belongs to thetryblock. - V is definitely unassigned after
ein every statement of the formthrowethat belongs to thetryblock. - V is definitely unassigned after every
assertstatement that occurs in thetryblock. - V is definitely unassigned before every
breakstatement that belongs to thetryblock and whose break target contains (or is) thetrystatement. - V is definitely unassigned before every
continuestatement that belongs to thetryblock and whose continue target contains thetrystatement.
- V is definitely unassigned after the
If a try statement does not have a finally block, then this rule also applies:
- V is [un]assigned after the
trystatement iff V is [un]assigned after thetryblock and V is [un]assigned after everycatchblock in thetrystatement.
If a try statement does have a finally block, then these rules also apply:
-
V is definitely assigned after the
trystatement iff at least one of the following is true:- V is definitely assigned after the
tryblock and V is definitely assigned after everycatchblock in thetrystatement. - V is definitely assigned after the
finallyblock.
- V is definitely assigned after the
-
V is definitely unassigned after the
trystatement iff V is definitely unassigned after thefinallyblock. -
V is definitely assigned before the
finallyblock iff V is definitely assigned before thetrystatement. -
V is definitely unassigned before the
finallyblock iff all of the following are true:- V is definitely unassigned after the
tryblock. - V is definitely unassigned before every
returnstatement that belongs to thetryblock. - V is definitely unassigned after
ein every statement of the formthrowethat belongs to thetryblock. - V is definitely unassigned after every
assertstatement that occurs in thetryblock. - V is definitely unassigned before every
breakstatement that belongs to thetryblock and whose break target contains (or is) thetrystatement. - V is definitely unassigned before every
continuestatement that belongs to thetryblock and whose continue target contains thetrystatement. - V is definitely unassigned after every
catchblock of thetrystatement.
- V is definitely unassigned after the