4

我尝试了以下代码

try {
  alertt("dddd");
} catch (e) {
    console.log(e.stack);
}

它会在 Google Chrome 和 Mozilla Firefox 中产生堆栈跟踪。但它在 Internet Explorer 中返回未定义。

有什么方法可以在 Internet Explorer 中获取堆栈跟踪?

4

3 回答 3

2

你的代码绝对可以在 IE11 中运行;我刚试过。我相信它至少也应该在 IE10 中工作。

您可能还对console.trace哪个为您提供堆栈跟踪感兴趣。这在 IE11 中绝对是新的,但这只是升级的另一个好理由——IE11 中的开发工具比以前好几个数量级。

于 2013-11-05T09:31:15.297 回答
-1

您可以使用MSDN文档e.description中提到的:

于 2013-11-05T09:01:50.577 回答
-2

句法 :

errorObj = new Error()
errorObj = new Error([number])
errorObj = new Error([number[, description]])

参数说明:

错误对象

Required. The variable name to which the Error object is assigned. The variable assignment is omitted when you create the error using a throw statement.

数字

Optional. Numeric value assigned to an error. Zero if omitted.

描述

Optional. Brief string that describes an error. Empty string if omitted.

例子

function checkInput(x) {
    try
    {
        if (isNaN(parseInt(x))) {
            throw new Error("Input is not a number.");
        }
    }
    catch(e)
    {
        document.write(e.description);
    }
}

checkInput("not a number");

注意:无论何时发生运行时错误,都会创建一个 Error 对象的实例来描述该错误。此实例有两个内在属性,其中包含 和 的error (description property)描述error number (number property)。有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/ie/1dk3k160%28v=vs.94%29.aspx

错误编号是一个 32 位的值。高 16 位字是设备代码,而低位字是实际错误代码。

于 2013-11-05T09:03:13.113 回答