uncaught-extender1.0.1 • Public • Published
unhandledRejectionwith custom listeners
npm install --production --save uncaught-extender
IMPORTANT! ensure this is declared as early as possible in your execution cycle
const uncaughtException unhandledRejection =processprocess
Start listening to any event type that matches your expected
// specificy your listeners for uncaught exceptionsprocess // catch-all event listenerprocessprocessprocessprocess// specificy your listeners for rejected promisesprocess // catch-all event listenerprocessprocessprocessprocess
continue with building your business logic normally, and when an exception is thrown or a Promise is rejected without a
catch that matches one of your listener functions, that function will be called with the
Error object passed as the only argument.
If no match is found, the
Error is thrown again to the main process.
const uncaughtException unhandledRejection =processprocessprocessprocessPromisethrow 'this will be caught by uncaughtException:TypeError'
'uncaughtException' is a crude mechanism for exception handling intended to be used only as a last resort. The event should not be used as an equivalent to
On Error Resume Next. Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the exception can cause additional unforeseen and unpredictable issues.
Learn more on the Official Node.js Documentation