为什么我的JScript(Windows脚本主机)退出0是一个未捕获的异常? [英] why does my JScript (windows script host) exit with 0 on an uncaught exception?

查看:110
本文介绍了为什么我的JScript(Windows脚本主机)退出0是一个未捕获的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些JScript使用ODBC连接做一些事情。 ODBC ActiveXObject对象抛出异常,并未在我的脚本中捕获。我预计该脚本将以非0值退出,但没有。任何人都知道为什么会出现这种情况,以及如何让它在未捕获的异常情况下以非0值退出?

解决方案

JScript引擎可以被认为是一个虚拟机。如果JScript引擎本身或脚本主机有某种形式的灾难性故障,您可能希望获得非零退出代码(例如,脚本主机找不到需要的DLL)。



但是,如果在此VM上运行的脚本程序会引发异常,即使是未处理引擎或主机故障的未处理的异常。



您可以做的是将整个脚本放在try块中,然后将异常抛出到catch中。脚本引擎会按照您希望原始处理的方式处理这个抛出的异常: -

  try 
{

//脚本的其余部分

}
catch(e)
{
throw(e); //返回非零退出代码
}


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?

解决方案

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
}

这篇关于为什么我的JScript(Windows脚本主机)退出0是一个未捕获的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆