How to catch uncaught exception in Promise

后端 未结 5 1519
悲哀的现实
悲哀的现实 2020-12-04 17:22

Is there any way to globally catch all exceptions including Promise exceptions. Example:

    window.onerror = function myErrorHandler(errorMsg, url, lineNumb         


        
5条回答
  •  日久生厌
    2020-12-04 17:58

    If you are using native Promise, it's pretty simple.
    You only need to .catch this reject some where.

    ajax(request).catch(function(rejected){
          console.log(rejected);
    });
    

    If I don't catch it somewhere, the uncaught in promise will keep showing. But If I catch it somewhere...

提交回复
热议问题