Code Lab

Modo entrevista. Cronômetro de 4 min, sem dicas e sem autocompletar

Your own error

FácilErrors4 min

Write a class FormatError for errors in a data format. It extends the built-in SyntaxError. For new FormatError('bad date') the message field is 'bad date' and the name field is 'FormatError'.

Exemplos

new FormatError('bad date').message

Retorna 'bad date'

new FormatError('bad date').name

Retorna 'FormatError'

new FormatError('bad date') instanceof SyntaxError

Retorna true

Fonte

Carregando o editor...
  1. message comes from the constructor, name is FormatError
  2. The error is a FormatError, a SyntaxError and an Error

Os testes ocultos rodam no envio