Bird
0
0

How can you combine handling both 'SIGINT' and 'uncaughtException' to ensure a graceful shutdown?

hard📝 Application Q9 of 15
Node.js - Error Handling Patterns
How can you combine handling both 'SIGINT' and 'uncaughtException' to ensure a graceful shutdown?
AOnly listen to 'SIGINT' and ignore 'uncaughtException'
BListen to both events, close server connections, then call process.exit() after cleanup
CCall process.exit() immediately in both handlers without cleanup
DRestart the server automatically inside 'uncaughtException' handler
Step-by-Step Solution
Solution:
  1. Step 1: Understand multiple event handling

    Both 'SIGINT' and 'uncaughtException' can trigger shutdown, so handle both.
  2. Step 2: Perform cleanup before exit

    Close server connections and cleanup resources before calling process.exit() in both handlers.
  3. Final Answer:

    Listen to both events, close server connections, then call process.exit() after cleanup -> Option B
  4. Quick Check:

    Handle all shutdown events with cleanup before exit [OK]
Quick Trick: Handle all shutdown signals with cleanup before exit [OK]
Common Mistakes:
  • Ignoring uncaughtException
  • Exiting immediately without cleanup
  • Restarting server inside error handler

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes