Node.js Best Practice Exception Handling

后端 未结 10 1607
遥遥无期
遥遥无期 2020-11-22 04:19

I just started trying out node.js a few days ago. I\'ve realized that the Node is terminated whenever I have an unhandled exception in my program. This is different than the

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 04:56

    You can catch uncaught exceptions, but it's of limited use. See http://debuggable.com/posts/node-js-dealing-with-uncaught-exceptions:4c933d54-1428-443c-928d-4e1ecbdd56cb

    monit, forever or upstart can be used to restart node process when it crashes. A graceful shutdown is best you can hope for (e.g. save all in-memory data in uncaught exception handler).

提交回复
热议问题