wsh - 获取在 Windows Script Host 中运行的 JScript 错误的行号

标签 wsh jscript

说,我有以下代码,我使用 Windows Script Host 作为 .JS 文件运行:

try
{
    ProduceAnError();
}
catch(e)
{
    //How to get an error line here?
}

有没有办法知道发生错误(异常)的错误行?

最佳答案

抱歉我的另一个回复。这不是很有帮助:P

我相信您正在寻找的是 ReferenceError 的 stack 属性。您可以使用传递给 catch 的参数访问它:

try {
  someUndefinedFunction("test");
} catch(e) {
  console.log(e.stack)
}

示例输出:
 ReferenceError: someUndefinedFunction is not defined
     at message (http://example.com/example.html:4:3)
     at <error: TypeError: Accessing selectionEnd on an input element that cannot have a selection.>
     at HTMLInputElement.onclick (http://example.com/example.html:25:4)

关于wsh - 获取在 Windows Script Host 中运行的 JScript 错误的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459098/

相关文章:

javascript - 如何使用 jquery 或 JavaScript 将元素属性与 Bootstrap Popover html 绑定(bind)?

javascript - 在原型(prototype)方法内部抛出异常,但未在外部 try catch 中捕获 (JavaScript)

windows - 如何隐藏 cmd.exe 和 cscript 命令提示符?

git - 在 Windows 中编写 Git 命令脚本

android - 如何以编程方式从另一个脚本在 sl4a 脚本编辑器中打开脚本?

javascript - 使用 Outlook 通过电子邮件发送临时文件

unit-testing - WSH 脚本单元测试框架

c# - 降级到 .net 2.0 时出现 JScript 错误