import {RuntimeError} from '@serenity-js/core/lib/errors'
public class | source

RuntimeError

Base class for custom errors that may occur during execution of a test scenario.

Extends:

Error → RuntimeError

Examples:

Custom Error definition
import { RuntimeError } from '@serenity-js/core';

export class CustomError extends RuntimeError {
  constructor(message: string, cause?: Error) {
      super(CustomError, message, cause);
  }
}
Sync error handling
try {
    operationThatMightThrowAnError();
} catch(error) {
    // catch and re-throw
    throw new CustomError('operationThatMightThrowAnError has failed', error);
}
Async error handling
operationThatMightRejectAPromise().catch(error => {
    // catch and re-throw
    throw new CustomError('operationThatMightThrowAnError has failed', error);
});

Constructor Summary

Public Constructor
public

constructor(type: Function, message: string, cause: Error)

Member Summary

Public Members
public

name: *

public

stack: string

Method Summary

Public Methods
public

toString(): string

Human-readable description

Public Constructors

public constructor(type: Function, message: string, cause: Error) source

Params:

NameTypeAttributeDescription
type Function

Constructor function used to instantiate a subclass of a RuntimeError

message string

Human-readable description of the error

cause Error
  • optional

The root cause of this RuntimeError, if any

Public Members

public name: * source

public stack: string source

Public Methods

public toString(): string source

Human-readable description

Returns:

string