Language concepts

Custom Error subclass

Try the free JavaScript compiler

Extends Error for domain-specific failures; initialize the inherited Error with super and optionally set a recognizable name.

Formal Syntax & Structure

javascript syntaxjavascript
class DomainError extends Error { /* ... */ }

Working Example

Example Snippetjavascript
class DomainError extends Error {constructor(m){super(m);this.name="DomainError";}} console.log(new DomainError("x").name);
JavaScript Reference