Docs (4.0.0)
class AppException method

type

Creates a new AppException class with the provided error name and message format string.

static

static type(name: string, format: StringConvertible): {
    new (...args: any[]): AppException;
}

Parameters

  • name — The error name, which should be unique to the type of application error
  • format — The format string that will be used to generate the error message, using constructor argument(s) as values for placeholders

Return value

A new AppException class, which itself can be instantiated using the new keyword.

Example

// Create a new error class and use it:
const ValidationError = AppException.type(
  "ValidationError", "Validation failed: %s");

try {
  throw new ValidationError("abc")
} catch (err) {
  if (err instanceof ValidationError) {
    err.message // => "Validation failed: abc"
    err.name // => "ValidationError"
  }
}

Related

  • class AppExceptionA class that represents an application error, including a localizable message.