title: How to catch exceptions when using Lombok's @Cleanup?
body: <p>I am using <a href="http://projectlombok.org/features/Cleanup.html" rel="nofollow">Lombok's @Cleanup</a> and even when I find it very useful, I cannot figure out how can I catch an exception being thrown by the main block of code that makes use of the resource to be cleant.</p>
  
  <p>My code is the following:</p>
  
  <pre><code>ScriptRunner runner = null;
  try {
      runner = scriptRunner();
  
      for (Resource sqlFile : sqlScripts) {
          runScript(sqlFile.getFile(), runner);
      }
  } catch (Exception ex) {
      log.error("Error found when attempting to run script", ex);
  } finally {
      if (runner != null) {
          runner.closeConnection();
      }
  }
  </code></pre>
  
  <p>With Lombok, I could simplify the code above this way:</p>
  
  <pre><code>@Cleanup("closeConnection") ScriptRunner runner = scriptRunner();
  
  for (Resource sqlFile : sqlScripts) {
      runScript(sqlFile.getFile(), runner);
  }
  </code></pre>
  
  <p>But I would be missing the possibility of catching any exception that might arise when the for loop executes. Is there any way to do this in an elegant way with Lombok? (i.e. other than programmatically using "try /catch?)</p>
  
  <p>Thanks very much in advance.</p>