Node.js - Error Handling PatternsHow can you convert unhandled promise rejections into exceptions that crash the Node.js process?AUse process.on('unhandledRejection', reason => { console.log(reason); })BUse process.on('unhandledRejection', reason => { throw reason; })CUse Promise.catch globally to catch all rejectionsDUse process.exit(1) immediately after Promise.rejectCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand converting rejection to exceptionThrowing the rejection reason inside the 'unhandledRejection' event handler causes the process to crash with an exception.Step 2: Correct event handler usageUsing process.on('unhandledRejection', reason => { throw reason; }) achieves this behavior.Final Answer:Use process.on('unhandledRejection', reason => { throw reason; }) -> Option BQuick Check:Throw in handler = crash on unhandled rejection [OK]Quick Trick: Throw reason inside unhandledRejection handler to crash [OK]Common Mistakes:Logging without throwing does not crash processTrying to catch all rejections globally with Promise.catchCalling process.exit immediately after rejection
Master "Error Handling Patterns" in Node.js9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Node.js Quizzes Child Processes - Why child processes are needed - Quiz 7medium Cluster Module - Why clustering matters for performance - Quiz 9hard Debugging and Profiling - Node.js built-in debugger - Quiz 14medium Debugging and Profiling - Console methods beyond log - Quiz 12easy Error Handling Patterns - Why robust error handling matters - Quiz 3easy Error Handling Patterns - Custom error classes - Quiz 6medium Timers and Scheduling - Recursive setTimeout vs setInterval - Quiz 3easy Timers and Scheduling - setImmediate vs process.nextTick - Quiz 13medium Worker Threads - SharedArrayBuffer for shared memory - Quiz 6medium Worker Threads - Creating worker threads - Quiz 5medium