title: Validate JavaScript-Code
body: <p>I use Java's ScriptEngine to execute JavaScript Code. I use the Invocable Interface, so that I can use the Script Code as a normal Java Object implementing a Java Interface.</p>
  
  <p>If the JavaScript Code </p>
  
  <ul>
  <li>is invalid</li>
  <li>does not follow the interface (missing methods, wrong return type, throws an exception etc.)</li>
  </ul>
  
  <p>I get an internal Exception from Rhino or an UndeclaredThrowableException while executing the code. Both are RuntimeExceptions, which are not "allowed" to catch. </p>
  
  <p>Is there a way to validate the code before executing? Or do I have to break the rule here and catch RuntimeExceptions? That would work for me, but what is the most elegant way?</p>