Java Reference
In-Depth Information
VariableModifiers
opt
_minus_final
is defined as
VariableModifiers
opt
without
final
, if
present.
#t
,
#primaryExc
, and
#suppressedExc
are automatically generated identifiers that are distinct
from any other identifiers (automatically generated or otherwise) that are in scope at the
point where the
try
-with-resources statement occurs.
If the
ResourceSpecification
declares one resource, then
ResourceSpecification_tail
is
empty (and the
try
-
catch
-
finally
statement is not itself a
try
-with-resources statement).
If the
ResourceSpecification
declares
n
> 1 resources, then
ResourceSpecification_tail
con-
sists of the 2nd, 3rd, ...,
n
'th resources declared in
ResourceSpecification
, in the same order
(and the
try
-
catch
-
finally
statement is itself a
try
-with-resources statement).
Reachability and definite assignment rules for the basic
try
-with-resources statement are
implicitly specified by the translation above.
In a basic
try
-with-resources statement that manages a single resource:
• If the initialization of the resource completes abruptly because of a
throw
of a value
V
, then the
try
-with-resources statement completes abruptly because of a
throw
of
the value
V
.
• If the initialization of the resource completes normally, and the
try
block completes
abruptly because of a
throw
of a value
V
, then:
♦ If the automatic closing of the resource completes normally, then the
try
-with-
resources statement completes abruptly because of a
throw
of the value
V
.
♦ If the automatic closing of the resource completes abruptly because of a
throw
of a value
V2
, then the
try
-with-resources statement completes abruptly be-
cause of a
throw
of value
V
with
V2
added to the suppressed exception list of
V
.
• If the initialization of the resource completes normally, and the
try
block completes
normally, and the automatic closing of the resource completes abruptly because of
a
throw
of a value
V
, then the
try
-with-resources statement completes abruptly be-
cause of a
throw
of the value
V
.
In a basic
try
-with-resources statement that manages multiple resources:
• If the initialization of a resource completes abruptly because of a
throw
of a value
V
, then:
♦ If the automatic closings of all successfully initialized resources (possibly
zero) complete normally, then the
try
-with-resources statement completes ab-
ruptly because of a
throw
of the value
V
.