Yes, close
won't be called. This is specified in the JLS section 14.20.3:
Resources are initialized in left-to-right order. If a resource fails to initialize (that is, its initializer expression throws an exception), then all resources initialized so far by the try-with-resources statement are closed. If all resources initialize successfully, the try block executes as normal and then all non-null resources of the try-with-resources statement are closed.
Resources are closed in the reverse order from that in which they were initialized. A resource is closed only if it initialized to a non-null value. An exception from the closing of one resource does not prevent the closing of other resources. Such an exception is suppressed if an exception was thrown previously by an initializer, the try block, or the closing of a resource.
In this case, an exception is thrown in the constructor so the resource is not initialized to a non-null value. Hence, the close
method isn't called.
Child
throws aFoo
", no instance ofChild
exists in the calling scope, soclose()
cannot be called. – Injectorclose
can be called on it. – Ean