LearnFrenzy
Sign in Take a free test

Error Handling · Find the Error · Question 4

Error: a custom error without super() Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

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

main.js
class OtpError extends Error {
  constructor(message) {
    this.name = "OtpError";
    this.message = message;
  }
}
throw new OtpError("OTP expired");
  • A It throws OtpError: OTP expired
  • B TypeError: name is read-only
  • C ReferenceError: a derived constructor must call super() before using this Correct
  • D SyntaxError
Correct Answer: Option C

Call super(message) first; it initialises the Error part of the object, including message and stack.

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