Bird
0
0

Which of these statements about try-catch in Node.js is true?

easy📝 Conceptual Q2 of 15
Node.js - Error Handling Patterns
Which of these statements about try-catch in Node.js is true?
A<code>try-catch</code> can catch both synchronous and asynchronous errors.
B<code>try-catch</code> only catches synchronous errors.
C<code>try-catch</code> automatically retries the failed code.
D<code>try-catch</code> is not used for error handling.
Step-by-Step Solution
Solution:
  1. Step 1: Differentiate error types

    In Node.js, try-catch works only for synchronous errors, not asynchronous ones like callbacks or promises.
  2. Step 2: Confirm correct statement

    Only synchronous errors are caught by try-catch, asynchronous errors require other handling methods.
  3. Final Answer:

    try-catch only catches synchronous errors. -> Option B
  4. Quick Check:

    try-catch sync errors only = A [OK]
Quick Trick: Try-catch catches sync errors, not async ones [OK]
Common Mistakes:
  • Assuming try-catch catches async errors
  • Thinking try-catch retries code automatically
  • Believing try-catch is not for error handling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes