Skip to content Skip to sidebar Skip to footer

Nodejs Process Crashed Without An Exception

I write a log entry to the log when an uncaught exception occurred in my nodejs app. process.on('uncaughtException', function (err) { log.warn('Caught exception. Exiting. error

Solution 1:

I will suggest you to add unhandledRejection as well. As the Node.js documentation is mentionning,

The unhandledRejection event is emitted whenever a Promise is rejected and no error handler is attached to the promise within a turn of the event loop. When programming with Promises, exceptions are encapsulated as "rejected promises". Rejections can be caught and handled using promise.catch() and are propagated through a Promise chain. The unhandledRejection event is useful for detecting and keeping track of promises that were rejected whose rejections have not yet been handled.

Here is an example of how to use it provided by Node.js again:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at:', p, 'reason:', reason);
  // application specific logging, throwing an error, or other logic here
});

somePromise.then((res) => {
  returnreportToUser(JSON.pasre(res)); // note the typo (`pasre`)
}); // no `.catch()` or `.then()`

Post a Comment for "Nodejs Process Crashed Without An Exception"