Is it possible to catch exceptions thrown in a JavaScript async callback?

前端 未结 7 1223
春和景丽
春和景丽 2020-11-27 04:15

Is there a way to catch exceptions in JavaScript callbacks? Is it even possible?

Uncaught Error: Invalid value for property 

7条回答
  •  清歌不尽
    2020-11-27 05:07

    I have detected the error by monkey patching the console logs.

    if(window.console && console.error){
        var old = console.error;
        console.error = function(){
            if(arguments[0].indexOf('Google Maps API error')!=-1){
                alert('Bad Google API Key '+ arguments[0]);
            }
            Array.prototype.unshift.call(arguments);
    
            old.apply(this, arguments);
        }
    }
    

提交回复
热议问题