title: Groovy end exception different from exception thrown
body: <p>I am running into an extremely strange behavior in Groovy. When I throw an exception from a closure in a Script, the end exception that was thrown was different.</p>
  
  <p>Here are the code and the details:</p>
  
  <pre><code>public class TestDelegate {
  
      def method(Closure closure) {
          closure.setResolveStrategy(Closure.DELEGATE_FIRST);
          closure.delegate = this;
          closure.call();
      }
  
      public static void main(String[] args) {
          // Make Script from File
          File dslFile = new File("src/Script.dsl");
          GroovyShell shell = new GroovyShell();
          Script dslScript = shell.parse(dslFile);
  
          TestDelegate myDelegate = new TestDelegate();
  
          dslScript.metaClass.methodMissing = {
              // will run method(closure)
              String name, arguments -&gt;
              myDelegate.invokeMethod(name, arguments);
          }
  
          dslScript.metaClass.propertyMissing = {
              String name -&gt;
  
              println "Will throw error now!"
              throw new MyOwnException("errrrror");
          }
  
          dslScript.run();
      }
  }
  
  class MyOwnException extends Exception {
      public MyOwnException(String message) {
          super(message);
      }
  }
  </code></pre>
  
  <p>Script.dsl: </p>
  
  <pre><code>method {
      println a;
  }
  </code></pre>
  
  <p>So the plan is that when I run the <code>main()</code> method in <code>TestDelegate</code>, it will run the DSL script, which calls for the method <code>method()</code>. Not finding it in the script, it will invoke <code>methodMissing</code>, which then invokes <code>method()</code> from <code>myDelegate</code>, which in turns invoke the closure, setting the delegate to the <code>testDelegate</code>. So far, so good. Then the closure is supposed to try printing out "a", which is not defined and will thus set off <code>propertyMissing</code>, which will will throw <code>MyOwnException</code>.</p>
  
  <p>When I run the code, however, I get the following output:</p>
  
  <pre><code>Will throw error now!
  Exception in thread "main" groovy.lang.MissingPropertyException: No such property: a for class: TestDelegate
  </code></pre>
  
  <p>Now, it must have reached that catch block, since it printed "Will throw error now!" It must have thrown <code>MyOwnException</code> too! But somewhere along the lines, <code>MyOwnException</code> was converted to <code>MissingPropertyException</code>, and I have no idea why. Does anyone have any idea?</p>
  
  <p>P.S. if I remove <code>closure.setResolveStrategy(Closure.DELEGATE_FIRST)</code> from <code>TestDelegate#method()</code>, the code acts as expected and throws <code>MyOwnException</code>. But I really need the <code>setResolveStrategy(Closure.DELEGATE_FIRST)</code> for my DSL project. And I would prefer to know the root cause of this rather than just removing a line or two and see that it works without understanding why.</p>