RuntimeError
Base class for custom errors that may occur during execution of a test scenario.
Extends:
Error → RuntimeError
Direct Subclasses:
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) |
Method Summary
Public Methods | ||
public |
toString(): string Human-readable description |
Public Constructors
public constructor(type: Function, message: string, cause: Error) source
Params:
Name | Type | Attribute | Description |
type | Function | Constructor function used to instantiate a subclass of a RuntimeError |
|
message | string | Human-readable description of the error |
|
cause | Error |
|
The root cause of this RuntimeError, if any |