Catch all unhandled javascript promise rejections

后端 未结 4 668
青春惊慌失措
青春惊慌失措 2020-11-27 05:01

I would like to catch all unhandled exceptions/rejections that take place within a javascript Promise. Is there a good method for catching them without adding a .catch

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 05:39

    Some libraries have their own APIs for doing this. Some browsers will report unhandled rejections (sooner or later).

    Actually, done probably does not do what you want. This is why it is not part of the spec. In any case, you still have to remember to call it.

    There is no reliable, cross-platform, cross-library way to do this.

提交回复
热议问题