Question 12
Back to Exercise
Why does try { setTimeout(() => { throw new Error("x"); }, 0); } catch (e) { … } not catch the error?
- A The callback runs after the try block has finished, so the error is thrown outside it Correct
- B Errors thrown in arrow functions cannot be caught
- C setTimeout catches errors itself
- D catch needs a finally block
Correct Answer: Option A
try/catch protects only code running during the try block. Handle errors inside the callback, or use promises/async-await.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!