LearnFrenzy
Sign in Take a free test

Error Handling · Find the Error · Question 8

Error: a bug inside the catch block Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
try {
  JSON.parse("{invalid}");
} catch (e) {
  console.log("Problem: " + e.message.toUppercase());
}
  • A It prints the message in capitals
  • B SyntaxError from JSON.parse is uncaught
  • C It prints Problem: undefined
  • D TypeError: toUppercase is not a function (it is toUpperCase) – an error thrown inside catch is not caught by the same try Correct
Correct Answer: Option D

The catch handled the SyntaxError, but then threw a new TypeError, which escapes.

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