【问题标题】:Is there a way to get line numbers or stack traces from an Error object in Internet Explorer?有没有办法从 Internet Explorer 中的错误对象中获取行号或堆栈跟踪?
【发布时间】:2012-03-01 05:37:21
【问题描述】:

为了ease debugging 一些在 Internet Explorer 中行为异常的棘手异步 Javascript 代码,我想知道是否有可能在给定错误对象的情况下获取有关其原始位置的有用信息。

Firefox、Chrome、Opera 和我想所有其他不错的浏览器都让我这样做:

try{
    throw Error('My custom error message');
}catch(e){
    console.log(e.stack)
}

但我尝试的所有属性(error.stackerror.lineNumber)都不能在 Internet Explorer 上运行。 有没有办法在 Internet Explorer 上仅使用 Javascript 获取此信息? 由于 IE REPL 将显示未处理异常的原始行号,即使它们被捕获并在不同的行中重新抛出,我假设我想要的信息存储在某处,但我不知道是否有公开的方式来获取它。

【问题讨论】:

    标签: javascript debugging internet-explorer exception exception-handling


    【解决方案1】:

    这些属性在 IE 中不可用。您可以使用arguments.callee 图表获得一些方法。但是,如果您有很多匿名函数或经常使用bind(),则此方法效果不佳。

    请参阅Closure Library's debug package 中的goog.debug.getStacktrace() 以获取示例实现。 goog.debug.normalizeErrorObject() 也可能对你有用。

    【讨论】:

    • 我有大量匿名函数和使用 bind 的东西。我搞砸了吗? :(
    • 试试看 :) 总比没有好。
    猜你喜欢
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    • 2012-06-18
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    相关资源
    最近更新 更多