Class Error

Error represents a generic exception.

All Known Subclasses 

APIException

Property Summary 

PropertyDescription
message: StringAn error message that provides details about the exception.
name: StringThe name of the error based on the constructor used.
stack: StringThe script stack trace.

Constructor Summary 

ConstructorDescription
Error()Constructs the Error object.
Error(String)Constructs the Error object using the specified message.

Method Summary 

MethodDescription
static captureStackTrace(Error, Function)Fills the stack property for the passed error.
toString()Returns a String representation of the Error.

Methods inherited from class Object 

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Property Details 

message 

message: String

An error message that provides details about the exception.


name 

name: String

The name of the error based on the constructor used.


stack 

stack: String

The script stack trace.

This property is filled on throwing or via an explicit call captureStackTrace(Error, Function).


Constructor Details 

Error() 

Error()

Constructs the Error object.


Error(String) 

Error(msg: String)

Constructs the Error object using the specified message.

Parameters:

  • msg - the message to use,.

Method Details 

captureStackTrace(Error, Function) 

static captureStackTrace(error: Error, constructorOpt: Function): void

Fills the stack property for the passed error.

The optional constructorOpt parameter allows you to pass in a function value. When collecting the stack trace all frames above the topmost call to this function, including that call, are left out of the stack trace. This can be useful to hide implementation details that won’t be useful to the user. The usual way of defining a custom error that captures a stack trace would be:

1function MyError() {
2    // fill the stack trace, but hide the call to MyError
3    Error.captureStackTrace(this, MyError);
4}

Parameters:

  • error - The error whose stack trace should be filled.
  • constructorOpt - An optional filter to hide the topmost stack frames.

API Version:

Available from version 21.2.

Note


toString() 

toString(): String

Returns a String representation of the Error.

Returns:

  • a String representation of the Error.