recherche

Maison  >  Questions et réponses  >  le corps du texte

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

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

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

    throw 'error';
})
PHPzPHPz2867 Il y a quelques jours644

répondre à tous(1)je répondrai

  • 大家讲道理

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

    express在外层catch住了异常,并且处理将异常信息输出到response中。

    web框架对于用户代码肯定是不信任的,所有调用用户代码,都有try catch,这样才能保证服务的稳定性。
    nodejs这样单进程单线程的环境,一个exception进程就挂了。

    répondre
    0
  • Annulerrépondre