UNPKG

@rimbu/common

Version:

Common types and objects used in many other Rimbu packages

47 lines 1.33 kB
/** * Throws an `Err.ForcedError` error when called. * @example * ```ts * const emptyMap = HashMap.empty<number, string>() * emptyMap.get(5, Err); * // throws: Err.CustomError(message: 'Err: forced to throw error') * ``` */ export function Err() { return ErrBase.msg('Err: Forced to throw error')(); } export var ErrBase; (function (ErrBase) { /** * A custom error instance. */ class CustomError { constructor(message) { this.message = message; } get name() { return this.constructor.name; } } ErrBase.CustomError = CustomError; class ForcedError extends CustomError { } ErrBase.ForcedError = ForcedError; /** * Returns a function that, when called, throws an `Err.ForcedError` with the given `message` string. * @param message - the message to put in the `Err.ForcedError` instance. * @example * ```ts * const emptyMap = HashMap.empty<number, string>() * emptyMap.get(5, ErrBase.msg('not found')); * // throws: Err.CustomError(message: 'not found') * ``` */ function msg(message) { return function () { throw new ErrBase.ForcedError(message); }; } ErrBase.msg = msg; })(ErrBase || (ErrBase = {})); //# sourceMappingURL=err.mjs.map