★ Constructor

The `RangeError` object constructor

RangeError()

Creates the RangeError instance that represents range error with the message built of the given described problem and its solution, optional min/max range, and an explicit identification on the given or stored error message template.

error.class.ts
constructor(
  problem: string,
  fix: string,
  id?: Id,
  min?: Min,
  max?: Max,
  template = RangeError.template
) {
  super(problem, fix, id, template, { min, max });
  this.#max = max;
  this.#min = min;
}

Parameters

problem:string

Description of the problem of a string type.

fix:string

A solution to the given problem of a string type.

id?:Id

Optional unique identification to the given problem of generic type variable Id.

min?:Min

The optional minimum range of generic type variable Min that causes an error to be thrown(or not thrown).

max?:Max

The optional maximum range of generic type variable Max that causes an error to be thrown(or not thrown).

template:string=RangError.template

Optional template of the error message of string type with the replaceable {problem}, {fix} and optional {id}, {max}, {min} tags. By default, the value is equal to the static property RangeError.template.

Example usage

// Example usage.
import { RangeError } from '@angular-package/error';

/*
  Returns
  RangeError: Problem(AE:427): The `age` parameter is too big, got 455 => Fix: Set the `age` parameter of the `setAge()` method between 9 and 27
*/
new RangeError(
  'The `age` parameter is too big, got 455', // Problem
  'Set the `age` parameter of the `setAge()` method', // Fix
  '(AE:427)', // Identification
  9,  // Minimum
  27 // Maximum range
);

Last updated