title: Main thread exception handler in Groovy script
body: <p>Having a problem with Groovy, I need to do some clean-up before exiting if uncaught exception was thrown in script, but can't find a way to do that.</p>
  
  <p>I've tried <i>Thread.setDefaultUncaughtExceptionHandler</i>, but seems it's not working for the main thread. Then, I have had a look stack trace, which lead me to GroovyStarter where I found that nice piece of code, which means that <i>Thread.setDefaultUncaughtExceptionHandler</i> is not really supposed to work:</p>
  
  <pre><code>public static void main(String args[]) {
     try {
         rootLoader(args);
     } catch (Throwable t) {
         t.printStackTrace();
     }
  }
  </code></pre>
  
  <p>just for the sake of example here is what I want to archive (this is not runnable script, just to show the concept):</p>
  
  <pre><code>def process = new ProcessBuilder(command).redirectErrorStream(true).start();
  
  onException = {
      process.destroy()
  }
  </code></pre>
  
  <p>Please, do not suggest to use try/catch, that's something I can think of myself :)</p>
  
  <p>PS: I'm a newbie to Groovy, so could be missing some obvious stuff.</p>