Add global try/catch to JavaScript

后端 未结 2 725
我寻月下人不归
我寻月下人不归 2020-12-14 07:37

Is there some way to wrap the entire page in a try/catch, so that I can catch any error from any script that is executing?

2条回答
  •  甜味超标
    2020-12-14 08:12

    Use window.onerror instead of a big try/catch.

    You could actually do some useful things in the error handler, like posting the error information to your server so you know when things are breaking on your page.

提交回复
热议问题