This exception is only thrown when using ScriptAny.checkValue. If checkValue is used to check arguments, the host application running a script should catch this exception in addition to catching ScriptRuntimeException and ScriptCompileException. Otherwise it makes sense to just use toValue after checking the type field of the ScriptAny and setting the NativeFunctionError flag appropriately then returning ScriptAny.UNDEFINED.
This variant holds primitive values as well as ScriptObject types.
This module implements the ScriptAny struct, which can hold any value type usable in the scripting language.