node.js - nodejs express throw 时为什么进程不会退出?
PHPz
PHPz 2017-04-17 14:22:53
0
1
647

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

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

    throw 'error';
})
PHPz
PHPz

学习是最好的投资!

reply all(1)
大家讲道理

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template