uncaughtException
The Node.js process event emitted when an error is thrown and nothing catches it; by default the process prints the stack trace and exits with code 1.
Carrying on after an uncaught exception runs with half-updated state, which can corrupt data or leak resources.
In more detail
A listener can log the error, but the program is then in an unknown state, so the only safe next step is to exit. A process supervisor should then restart it in a clean state.
Related terms
- uncaughtExceptionMonitor — A Node.js process event emitted just before an uncaught exception is handled, letting you record it without stopping the crash.
- exception — An error object a program raises to stop normal flow and report that something went wrong.
- process supervisor — A program that starts processes, watches them and restarts them if they exit, such as systemd or a container platform.
Taught in
- Global Error Trapping: uncaughtException & Exits — Node.js Internals & Backend Services