Hello, 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.
If the JavaScript Code
- is invalid
- does not follow the interface (missing methods, wrong return type, throws an exception etc.)
I get an internal Exception from Rhino or an UndeclaredThrowableException while executing the code. Both are RuntimeExceptions, which are not "allowed" to catch.
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?