In the try
-with-resources construct of Java 7, I can declare a resource in the try
statement, and it will be closed autom
This syntax is called Extended try-with-resources
As per JLS:
try ResourceSpecification
Block
Catchesopt
Finallyopt
Will be translated to:
try {
try ResourceSpecification
Block
}
Catchesopt
Finallyopt
So, in your example, your resource will be limited to inner try block, so not available for outer try/catch/finally
.
EDIT:
my question does not have nested try blocks
By explicitly adding catch/finally block in your code, you are introducing nested try blocks.