Skip to content

Latest commit

 

History

History
18 lines (11 loc) · 597 Bytes

how_to_catch_unhandled_promise_rejections.md

File metadata and controls

18 lines (11 loc) · 597 Bytes

How to catch unhandled promise rejections

Listen for unhandled promise rejections to prevent unexpected application crashes.

process.on('unhandledRejection', (reason, promise) => {
  console.error('Unhandled Rejection at:', promise, 'reason:', reason);
});

// Example of an unhandled rejection
Promise.reject(new Error('Unhandled error'));

Tags: advanced, JavaScript, Promises, Error Handling