Bird
0
0

What will be the output of this Node.js code?

medium📝 component behavior Q13 of 15
Node.js - Error Handling Patterns
What will be the output of this Node.js code?
try {
  throw new Error('Oops!');
} catch (e) {
  console.log('Caught:', e.message);
} finally {
  console.log('Done');
}
ACaught: Oops!\nDone
BDone\nCaught: Oops!
COops!\nDone
DError: Oops!\nDone
Step-by-Step Solution
Solution:
  1. Step 1: Understand the try-catch-finally flow

    The throw triggers an error caught by catch, which logs 'Caught: Oops!'.
  2. Step 2: Recognize finally block runs last

    The finally block always runs, logging 'Done' after the catch.
  3. Final Answer:

    Caught: Oops!\nDone -> Option A
  4. Quick Check:

    Catch logs error, finally logs done = A [OK]
Quick Trick: Catch runs before finally; order matters [OK]
Common Mistakes:
  • Thinking finally runs before catch
  • Expecting error to crash program
  • Confusing error message with error object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes