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

前端 未结 7 1182
春和景丽
春和景丽 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:08

    The reason it won't catch anything in your example is because once the geocode() callback is called, the try/catch block is over. Therefore the geocode() callback is executed outside the scope of the try block and thus not catchable by it.

    As far as I know, it is not possible to catch exceptions thrown in JavaScript callbacks (at least, not in any straightforward manner).

    0 讨论(0)
提交回复
热议问题