Chrome: Will an error in code invoked from the dev console trigger [removed]?

后端 未结 1 781
太阳男子
太阳男子 2020-12-15 16:26

I\'m trying to debug our handling of window.onerror. I\'ve created a function that will throw an error (invoking another function that does not exist). I\'ve tried calling

相关标签:
1条回答
  • 2020-12-15 17:09

    They don't (in Chrome where I tested), easy way to test is

    window.onerror = function () {console.log('error!');};
    throw new Error();
    // Error
    

    You can make them do it if you defer them, though

    window.setTimeout(function() {throw new Error()}, 0);
    // error!
    // Uncaught Error
    
    0 讨论(0)
提交回复
热议问题