Answer

Answer

t.me/js_test

Ответ:

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

Обьяснение:

Создаём класс FormatError, которые наследуется от встроенноего класса ошибки SyntaxError, в конструкторе дочернего класса вызываем конструктор родительского класса и присваиваем this.name = "FormatError"

Код для проверки:

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

const err = new FormatError("ошибка форматирования");

console.log(err.message); // ошибка форматирования
console.log(err.name); // FormatError
console.log(err.stack); // stack

console.log(err instanceof FormatError); // true
console.log(err instanceof SyntaxError); // true

Report Page