【发布时间】:2016-01-27 08:32:59
【问题描述】:
我希望浏览器在发生类型错误时显示错误消息。
can not read property something of undefined 或 undefined reference 等错误。
new Promise(function(resolve,reject){
// do stuff ...
reject('something logical is wrong');
}).catch(e => console.error(e));
new Promise(function(resolve,reject){
// do stuff, and a syntax error :/
var a = { };
a.something.otherthing = 1; /* we have an error here */
// ...
}).catch(e => console.error(e));
在第一个示例中,错误是一个逻辑错误,可以在 catch(..) 块中catch。
但在第二个例子中,这是一个明显的开发错误,在开发新东西时一直发生。我不想抓住它,我希望浏览器像控制台中的其他错误一样向我显示错误。
我希望能够打开 chrome pause on exceptions 并查看其他变量的状态。我想在控制台中查看堆栈跟踪。
我希望它表现得像一个正常错误。
有什么想法吗?
【问题讨论】:
-
使用您的第二个示例,我在控制台
TypeError: Cannot set property 'otherthing' of undefined中收到以下错误。这不是你想要发生的吗?承诺未决,但这是一个不同的问题。 -
我想要错误的行号,堆栈跟踪。
-
@AdamJeffers 我也想使用 chrome 打破异常功能。
-
要获得正确的错误行号,我认为您需要删除 catch()?这是一个有趣的问题,我觉得有必要进一步调查!
-
FWIW 与您的示例一样,我在 Chrome 和 Firefox 的控制台中都获得了
TypeError的行号,在 Firefox 中,我还在控制台中获得了堆栈跟踪。