在以下代码中,我有意抛出错误,但在Chrome(仅用于测试目的)中,它没有滚动到catch。如何将错误滚动到父级范围?
Chrome的回复如下:
try {
setTimeout(function() {
console.log("Throwing Error...");
throw({message:"Ouch!"});
}, 500);
} catch(e) {
console.log(e.message);
}
Chrome的回复如下:
Uncaught #<Object>
(anonymous function)
以下是我正在处理的完整示例;当我需要“bob”时,它(有意地)超时。我想捕获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);
}
})();