在下面的代码中,我故意抛出一个错误,但在 Chrome 中(仅用于测试目的)它不会汇总到问题。如何将错误汇总到父级范围?
try {
setTimeout(function() {
console.log("Throwing Error...");
throw({message:"Ouch!"});
}, 500);
} catch(e) {
console.log(e.message);
}
Chrome 回复:
Uncaught #<Object>
(anonymous function)
这是我正在使用的完整示例;当我需要“鲍勃”时,它(故意)超时。我想捕获 requirejs 错误,以便我可以使用更强大的应用程序错误系统来通知学习者。
(function() {
try {
var scriptVersion = "1.0.0.1"
window.onload = function() {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "//content.com/pkg/" + scriptVersion + "/require-jquery.js";
script.async = false;
script.done = false;
// OnReadyStateChange for older IE browsers
script.onload = script.onreadystatechange = function() {
if(!(this.done) && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
this.done = true;
require.config({
baseUrl: "//content.com/pkg/" + scriptVersion
});
require(["bob"]);
}
}
document.getElementsByTagName("head")[0].appendChild(script);
}
} catch(e) {
console.log(e);
}
})();