Java Reference
In-Depth Information
♦ If the automatic closings of all successfully initialized resources (possibly
zero) complete abruptly because of
throw
s of values
V1
...
Vn
, then the
try
-with-
resources statement completes abruptly because of a
throw
of the value
V
with
any remaining values
V1
...
Vn
added to the suppressed exception list of
V
.
• If the initialization of all resources completes normally, and the
try
block completes
abruptly because of a
throw
of a value
V
, then:
♦ If the automatic closings of all initialized resources complete normally, then
the
try
-with-resources statement completes abruptly because of a
throw
of the
value
V
.
♦ If the automatic closings of one or more initialized resources complete ab-
ruptly because of
throw
s of values
V1
...
Vn
, then the
try
-with-resources state-
ment completes abruptly because of a
throw
of the value
V
with any remaining
values
V1
...
Vn
added to the suppressed exception list of
V
.
• If the initialization of every resource completes normally, and the
try
block com-
pletes normally, then:
♦ If one automatic closing of an initialized resource completes abruptly because
of a
throw
of value
V
, and all other automatic closings of initialized resources
complete normally, then the
try
-with-resources statement completes abruptly
because of a
throw
of the value
V
.
♦ If more than one automatic closing of an initialized resource completes ab-
ruptly because of
throw
s of values
V1
...
Vn
, then the
try
-with-resources state-
ment completes abruptly because of a
throw
of the value
V1
with any remaining
values
V2
...
Vn
added to the suppressed exception list of
V1
(where
V1
is the
exception from the rightmost resource failing to close and
Vn
is the exception
from the leftmost resource failing to close).
14.20.3.2. Extended try-with-resources
A
try
-with-resources statement with at least one
catch
clause and/or a
finally
clause is called
an
extended
try
-with-resources statement.
The meaning of an extended
try
-with-resources statement:
try
ResourceSpecification
Block
Catches
opt
Finally
opt