search

Home  >  Q&A  >  body text

node.js - nodejs express throw 时为什么进程不会退出?

今天碰到一个很奇怪的问题,就是在代码中抛出一个异常时node进程居然不会退出,throw的内容会作为respose内容,且通过uncaughtException事件还无法捕获,请各位大侠指点.

app.use(function(req,res,next){

    throw 'error';
})
PHPzPHPz2785 days ago604

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 14:24:53

    Express catches the exception in the outer layer and processes the exception information and outputs it to the response.

    The web framework definitely does not trust user code. All calls to user code have try catch, so as to ensure the stability of the service.
    In a single-process single-thread environment like nodejs, an exception process will hang.

    reply
    0
  • Cancelreply