The JScript engine can be thought of as a virtual machine. If the JScript engine itself or the host script should have some kind of catastrophic error, you can expect to get a zero exit code (for example, the host script could not find one of the DLLs that it needs).
However, if a script program running on this “virtual machine” throws an even unhandled exception, which is not a failure in the engine or host.
What you can do is put the whole script in a try block and then just throw an exception in catch. The scripting engine will handle this thrown exception exactly as you would like the original to be processed: -
try { // the rest of your script } catch(e) { throw(e); // returns nonzero exit code }
source share