title: Can exception masking be completely prevented with try-with-resources statement
body: <p>I'm aware that try-with-resources statement was introduced to cure (or) prevent exception masking. </p>
  
  <p>Consider the following code:</p>
  
  <pre><code>class TestExceptionSuppressing {
      public static void main(String[] args) {
          try {
              testMethod();
          } catch (Exception e) {
              System.out.println(e.getMessage());
              for (Throwable t : e.getSuppressed()) {
                  System.err.println("Suppressed Exceptions List: " + t);
              }
          }
      }
  
      static void testMethod() {
          try (InnerClass inner = new InnerClass()) {
              throw new IOException("Exception thrown within try block");
          } catch (Exception e) {
              throw new RuntimeException(
                      "Exception thrown within catch block.Hence exception thrown within try block will be lost (or) masked");
          }
      }
  
      static class InnerClass implements AutoCloseable {
  
          @Override
          public void close() throws Exception {
              throw new Exception("Exception thrown in close method will be tacked on to existing exceptions");
          }
      }
  }
  </code></pre>
  
  <p>Output: <em>Exception thrown within catch block.Hence exception thrown within try block will be lost (or) masked</em></p>
  
  <p>Apparently, exception thrown in catch block of testMethod() has masked both the io exception thrown in try block and also the exception suppressed and added to this io exception(thrown in close method )</p>
  
  <p>This code example might prove that try-with-resources may not completely prevent exception masking.</p>
  
  <p>I'm aware things are mixed up in here and might be confused but is a possible case to happen. <strong>My question is, is there a way to prevent this scenario i.e. exception masking to still happen even when using try-with-resources statement?</strong></p>