Since you are using a try-with-resource statement, and if by "released" you mean "closed" then yes.
Any instance implementing AutoCloseable
opened in a try-with-resources statement is .close()
d right before catch
, so in your case unverifiedStream
will be closed before you catch Exception
.
It should also be noted that Closeable
extends AutoCloseable
, so all existing classes implementing Closeable
will "magically" work within a try-with-resources statement.
Sample code:
public final class AutoCloseableExample
{
private static final class Foo
implements AutoCloseable
{
@Override
public void close()
throws IOException
{
System.out.println("foo");
throw new IOException();
}
}
public static void main(final String... args)
{
try (
final Foo foo = new Foo();
) {
System.out.println("try block");
} catch (IOException ignored) {
System.out.println("exception!");
} finally {
System.out.println("finally block");
}
}
}
Output:
try block
foo
exception!
finally block
Side note: you should not catch Exception
since this also catches all unchecked exceptions (ie, RuntimeException
and derivates). Catch more specific exceptions instead.