en.javascript.info/1-js/10-error-handling/2-custom-errors/1-format-error/solution.md
hrodward 2bd1854c55
Update solution.md
Wouldn't this solution be more flexible?
2019-10-25 14:25:44 +02:00

354 B

class FormatError extends SyntaxError {
  constructor(message) {
    super(message);
    this.name = this.constructor.name;
  }
}

let err = new FormatError("formatting error");

alert( err.message ); // formatting error
alert( err.name ); // FormatError
alert( err.stack ); // stack

alert( err instanceof SyntaxError ); // true