Java Reference
In-Depth Information
A try -with-resources statement with a ResourceSpecification clause that declares multiple
resources is treated as if it were multiple try -with-resources statements, each of which has
a ResourceSpecification clause that declares a single Resource . When a try -with-resources
statement with n Resources ( n > 1) is translated, the result is a try -with-resources statement
with n -1 Resources . After n such translations, there are n nested try - catch - finally statements,
and the overall translation is complete.
14.20.3.1. Basic try-with-resources
A try -with-resources statement with no catch clauses or finally clause is called a basic try -
with-resources statement.
The meaning of a basic try -with-resources statement:
try ( VariableModifiers opt R Identifier = Expression ...)
Block
is given by the following translation to a local variable declaration and a try - catch - finally
statement:
Click here to view code image
{
final VariableModifiers_minus_final R Identifier = Expression ;
Throwable #primaryExc = null;
try ResourceSpecification_tail
Block
catch (Throwable #t) {
#primaryExc = #t;
throw #t;
} finally {
if ( Identifier != null) {
if (#primaryExc != null) {
try {
Identifier .close();
} catch (Throwable #suppressedExc) {
#primaryExc.addSuppressed(#suppressedExc);
}
} else {
Identifier .close();
}
}
}
}
Search WWH ::




Custom Search