Pages

Saturday, April 20, 2019

Nodejs handling uncaught exceptions globally

For unhandled exceptions:
process.on('uncaughtException', err => {
  console.error('There was an uncaught error', err)
  process.exit(1) //mandatory (as per the Node.js docs)
})

Here  uncaughtException event listener will be called for every such scenario.

Source: here

For unhandled Promise rejection:


process.on('unhandledRejection', err => { console.error('There was an uncaught error', err) process.exit(1) //mandatory (as per the Node.js docs) })


Here unhandledRejection event listener will also be called for every such scenario.

No comments :

Post a Comment