title: Java with Groovy handling of closures throwing Exceptions
body: <p>We have a system that is possible to customise using groovy scripts and I've spotted a very strange effect on the type of exceptions throw from these scripts. </p>
  
  <p>We have a groovy script with the following:</p>
  
  <pre><code>process {
     throw new Exception("weeee")
  }
  </code></pre>
  
  <p>Process is defined as a Closure in the base class of the script:</p>
  
  <pre><code>public abstract class ScriptBaseClass extends Script {
     Closure process;
  
     public void process( Closure code ) {
        process = (Closure) code.clone();
     } 
  }
  </code></pre>
  
  <p>In the <strong>Java class</strong> that actually runs the scripts we have the following method (omitted all the set up code as it doesn't seem relevant):</p>
  
  <pre><code>public void process() {
     try {
        script.process.call();
     } catch (Exception e) {
        logger.debug("exception thrown from groovy script", e);
        throw e;
     }
  }
  </code></pre>
  
  <p>Note the process method here doesn't declare it throws any exceptions. However it quite clearly re-throws the Exception e that it caught. This code is valid, it compiles and runs quite happily. It throws the Exception as I wanted.</p>
  
  <p>Does any one know how this is legal code? In theory I shouldn't be able to throw a checked exception out of a method that doesn't declare that it throws it.</p>