Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with node.js exceptions

We're looking to use node.js for a highly dynamic project. Traditionally, we've used Java and, when faced with an unhandled exception, an error is thrown but the web application (usually) continues to serve other requests.

With node, however, the same scenario causes the process to terminate. I'd hate to think what would happen if we deployed this system to production and the whole server crashed because of an unhandled exception.

I was wondering if there are tutorials / tools / etc to help deal with the problem of dealing with exceptions. For example, is there a way to add a global last-resort-type exception that?

like image 307
NRaf Avatar asked Feb 22 '26 15:02

NRaf


1 Answers

process.on('uncaughtException', function (err){
  console.error(err)
})
like image 135
danmactough Avatar answered Feb 25 '26 05:02

danmactough