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

Reply via email to