wsh – 获取Windows脚本宿主中运行的JScript中的错误行号

前端之家收集整理的这篇文章主要介绍了wsh – 获取Windows脚本宿主中运行的JScript中的错误行号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
说,我有以下代码,我使用 Windows脚本宿主作为.JS文件运行:

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

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

解决方法

对不起我的其他回复.这不是很有帮助:P

我相信你要找的是ReferenceError的堆栈属性.您可以使用传递给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)

猜你在找的Windows相关文章