Complete the code to define a custom error class named MyError.
class MyError extends [1] { constructor(message) { super(message); this.name = 'MyError'; } }
The custom error class should extend the built-in Error class to behave like an error.
Complete the code to throw a new instance of the custom error MyError with a message.
throw new [1]('Something went wrong');
new keyword.To throw the custom error, create a new instance of MyError.
Fix the error in the custom error class by completing the missing call to the parent constructor.
class ValidationError extends Error { constructor(message) { [1]; this.name = 'ValidationError'; } }
Calling super(message) ensures the base Error class is properly initialized with the message.
Fill both blanks to create a custom error class named DatabaseError that sets the name and captures the stack trace.
class DatabaseError extends Error { constructor(message) { super(message); this.name = [1]; if (Error.captureStackTrace) { Error.captureStackTrace(this, [2]); } } }
The name property should be set to the string 'DatabaseError'. The captureStackTrace method takes the class itself as the second argument.
Fill all three blanks to create a custom error class ApiError that accepts a message and a status code, sets the name, and stores the status code.
class ApiError extends Error { constructor(message, statusCode) { super([1]); this.name = [2]; this.statusCode = [3]; } }
The constructor passes message to super, sets name to 'ApiError', and stores the statusCode property.