Search code examples
javascriptjvmnashorn

Nashorn Javascript: NativeTypeError


The Nashorn Javascript engine (part of Java 8) reports some exceptions, esp. regarding method binding errors like arity or type mismatches, as a NativeTypeError-instance, which does not have a cause relation to get any exception and is therefore very opaque to me (I'd like to report as much as possible back to the script user).

Is there a documented method to get root causes or further information from a NativeTypeError-instance?


Solution

  • Answering my own question: the semantics of NativeTypeError are described in the ECMAScript standard (ECMA-262, sec. 15.11.7). Instances of NativeTypeError expose a public field message, which is of type Object, but is most likely a String for all circumstances I've encountered it.