Exceptions thrown in asynchronous javascript not caught

前端 未结 3 2612
一整个雨季
一整个雨季 2021-02-20 17:46

Basically, why isn\'t this exception caught?

var http = require(\'http\'),
    options = {
      host: \'www.crash-boom-bang-please.com\',
      port: 80,
               


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 18:29

    When you are throwing the error the try {} block has been long left, as the callback is invoked asynchronously outside of the try/catch. So you cannot catch it.

    Do whatever you want to do in case of an error inside the error callback function.

提交回复
热议问题