作者:我想去海边6_414 | 来源:互联网 | 2023-05-18 04:36
IsthereanywaytogloballycatchallexceptionsincludingPromiseexceptions.Example:是否有办法全局捕获所有
Is there any way to globally catch all exceptions including Promise exceptions. Example:
是否有办法全局捕获所有异常,包括承诺异常。例子:
window.Onerror= function myErrorHandler(errorMsg, url, lineNumber) {
alert("Error occured: " + errorMsg);//or any message
return false;
}
var myClass = function(){
}
var pr = new Promise(function(resolve, react){
var myInstance = new myClass();
myInstance.undefinedFunction(); // this will throw Exception
resolve(myInstance);
});
pr.then(function(result){
console.log(result);
});
// i know right will be this:
// pr.then(function(result){
// console.log(result);
// }).catch(function(e){
// console.log(e);
// });
This script will silently die without error. Nothing in firebug.
这个脚本将无声地死去,不会出错。firebug。
My question is if I do a mistake and forgot to catch it is there any way to catch it globally?
我的问题是,如果我犯了一个错误,却忘了抓住它,有没有办法在全球范围内抓住它?
5 个解决方案