I have some JScript which does some stuff with an ODBC connection. An exception was thrown by the ODBC ActiveXObject object and not caught in my script. I expected that the script would exit with an non 0 value but it didn't. Anyone know why this is the case and how to get it to exit with a non 0 value on an uncaught exception?
views:
442answers:
1
+1
A:
The JScript engine can be thought of as a virtual machine. If the JScript engine itself or the script host were to have some form of catastrophic failure you could expect to get a non zero exit code (for example an the script host couldn't find one of the DLLs it needs).
However if the script program being run on this 'VM' throws an exception even an unhandled one that does not constitute a failure in the engine or the host.
What you can do is place the whole script in a try block and use WScript.Quit in the catch:-
try
{
// the rest of your script
}
catch(e)
{
WScript.Quit(1); // returns exit code 1
}
AnthonyWJones
2009-04-07 09:09:14
Note that VBScript suffers from the same issue, but is much harder to achieve a fix - one of the reasons I tend to prefer JScript to VBScript. See http://stackoverflow.com/questions/2929715/capture-any-error-in-vbscript for details.
bacar
2010-09-15 22:38:54