review request for 7021209, use try-with-resources in lang, math, util
Joe Darcy
joe.darcy at oracle.com
Tue Feb 22 03:23:40 UTC 2011
David Holmes wrote:
> Hi Stuart,
>
> I'm unclear how try-with-resources applies in different cases. For
> example, here in Package.java:
>
> private static Manifest loadManifest(String fn) {
> try (FileInputStream fis = new FileInputStream(fn);
> JarInputStream jis = new JarInputStream(fis, false))
> {
> return jis.getManifest();
> } catch (IOException e) {
> return null;
> }
> }
>
> from which code will the the explicit catch block actually catch
> IOException?
It will catch exceptions from jis.getManifest and from the
compiler-generated close calls on fis and jis.
> Does this act as-if it were written:
>
> try {
> try (FileInputStream fis = new FileInputStream(fn);
> JarInputStream jis = new JarInputStream(fis, false))
> {
> return jis.getManifest();
> }
> } catch (IOException e) {
> return null;
> }
Yes it does.
-Joe
More information about the core-libs-dev
mailing list