Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ErrorConstructor

Hierarchy

  • ErrorConstructor

Index

Properties

Methods

Properties

stackTraceLimit

stackTraceLimit: number

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or `Error.captureStackTrace(obj))``.

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Methods

captureStackTrace

  • captureStackTrace<T>(targetObject: T, constructorOpt?: object): void
  • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which `Error.captureStackTrace()`` was called.

    const myObject = {};
    Error.captureStackTrace(myObject);
    myObject.stack  // similar to `new Error().stack`
    

    The first line of the trace, instead of being prefixed with ErrorType : message, will be the result of calling `targetObject.toString()``.

    The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

    The constructorOpt argument is useful for hiding implementation details of error generation from an end user. For instance:

    function MyError() {
      Error.captureStackTrace(this, MyError);
    }
    
    // Without passing MyError to captureStackTrace, the MyError
    // frame would should up in the .stack property. by passing
    // the constructor, we omit that frame and all frames above it.
    new MyError().stack
    

    Type parameters

    • T: object

    Parameters

    • targetObject: T
    • Optional constructorOpt: object

    Returns void

Generated using TypeDoc