【发布时间】:2018-10-10 03:58:53
【问题描述】:
我正在尝试为我的网络应用实现“全局错误处理程序”。
作为测试,我正在运行这段代码:
nope(); // this function does not exist
不出所料,在控制台中我得到:
Uncaught ReferenceError: nope is not defined
我正在尝试通过我的错误处理函数访问此文本,但我的两种方法都只提供更通用的消息(Chrome 61):
// approach #1
window.onerror = function(message) {
console.log(message); // "Script error."
};
// approach #2
window.addEventListener("error", function(e) {
console.log(e.message); // "Script error."
});
有没有更好的方法来获取更详细的错误消息? 有这类东西的图书馆吗?
【问题讨论】: