LearnFrenzy
Sign in Take a free test

Callbacks · Callbacks MCQ · Question 12

try/catch and async callbacks Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links