LearnFrenzy
Sign in Take a free test

Error Handling · Find the Error · Question 5

Error: a custom error class called without new Answer, explanation & discussion

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

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

main.js
class QuotaError extends Error {
  constructor(message) {
    super(message);
    this.name = "QuotaError";
  }
}
throw QuotaError("Daily limit reached");
  • A TypeError: class constructors cannot be invoked without new – write throw new QuotaError(…) Correct
  • B It throws QuotaError: Daily limit reached
  • C ReferenceError
  • D It returns undefined
Correct Answer: Option A

Built-in Error("msg") works without new, which misleads people; classes never do.

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