加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 05:40:18 所属栏目:Windows 来源:网络整理
导读:说,我有以下代码,我使用 Windows脚本宿主作为.JS文件运行: try{ ProduceAnError();}catch(e){ //How to get an error line here?} 有没有办法知道发生错误(异常)的错误行? 解决方法 对不起我的其他回复.这不是很有帮助:P 我相信你要找的是ReferenceError
说,我有以下代码,我使用 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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读