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

ahm*_*md0 5 wsh jscript

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

try
{
    ProduceAnError();
}
catch(e)
{
    //How to get an error line here?
}
Run Code Online (Sandbox Code Playgroud)

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

Jos*_*kle 0

抱歉我的其他回复。这不是很有帮助:P

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

try {
  someUndefinedFunction("test");
} catch(e) {
  console.log(e.stack)
}
Run Code Online (Sandbox Code Playgroud)

示例输出:

 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)
Run Code Online (Sandbox Code Playgroud)