why does my JScript (windows script host) exit with 0 on an uncaught exception?

≡放荡痞女 提交于 2019-12-03 19:28:40
AnthonyWJones

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 then just throw the exception in the catch. The scripting engine will handle this thrown exception exactly as you wanted the original handled:-

try
{

  // the rest of your script

}
catch(e)
{
  throw(e);  // returns nonzero exit code
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!