Unhandled Rejections: What to Do in Production
On this page
What Is an Unhandled Rejection?
A promise rejection that is not caught anywhere in the code.
Example
async function fail() {
throw new Error('boom');
}
fail();
Process-Level Handling
process.on('unhandledRejection', (reason) => {
console.error('Unhandled rejection:', reason);
});
Why This Is Dangerous
Unhandled rejections may crash the process or leave the application in an inconsistent state.
Production Rule
- Never ignore promise rejections.
- Centralize error handling.
- Crash intentionally if state is corrupted.