Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NamedError

A customizable Error, that may be created from an existing Error

Hierarchy

  • Error
    • NamedError

Constructors

constructor

  • new NamedError(name: string, message: string, existingError?: unknown): NamedError
  • creates a new Error with the given name and message.

    • Additionally receives a givenError which will have concatenated message and stack with the newly created error.
    • If the givenError is not typeof Error an Error will be created of it.

    Usage

    const existingError = new RangeError('some message')
    const myError = new NamedError('MyError', 'this is my custom Error', existingError);
    
    // in a try-catch-phrase
    try {
      // some dangerous stuff
    } catch (error) {
      Loxer.error(new NamedError('DangerousStuffError', 'failed to do some dangerous stuff', error));
    }
    

    Parameters

    • name: string

      The Error.name

    • message: string

      The Error.message which may be concatenated with the givenError.message

    • Optional existingError: unknown

      An optional error (of any type) which will be concatenated

    Returns NamedError

Properties

name

name: string

message

message: string

Optional stack

stack: string

Static Optional prepareStackTrace

prepareStackTrace: function

Type declaration

    • (err: Error, stackTraces: CallSite[]): any
    • Optional override for formatting stack traces

      Parameters

      • err: Error
      • stackTraces: CallSite[]

      Returns any

Static stackTraceLimit

stackTraceLimit: number

Methods

Static captureStackTrace

  • captureStackTrace(targetObject: object, constructorOpt?: Function): void
  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • Optional constructorOpt: Function

    Returns void

Generated using TypeDoc