Why is my JScript (Windows script host) exiting from 0 on an uncaught exception?

I have a JScript that does some things with an ODBC connection. The exception was thrown by the ODBC ActiveXObject and did not fall into my script. I expected the script to exit with a non-zero value, but that is not the case. Does anyone know why this is and how to make it exit with a value of not 0 on an uncaught exception?

+3
source share
1 answer

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 } 
+2
source

Source: https://habr.com/ru/post/1311215/


All Articles