Unhandled Exception Management
suggest changeAn uncaught exception indicates that the application reached an unexpected state. Handle expected operational errors where they occur. Reserve the process-level hook for unexpected failures.
Do not swallow an exception and continue normal work:
process.on('uncaughtException', error => {
console.error(error);
});
The handler may synchronously log the error before shutdown. Use a service manager or container orchestrator to restart the terminated process:
process.on('uncaughtException', error => {
console.error(error);
process.exit(1);
});
The process may be in an undefined state after an uncaught exception, so the handler should perform only essential synchronous cleanup before exiting.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents