Documentation

AppException​.type()

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

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

Parameters

Return value

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

Examples

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

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

Related