@rimbu/common
Version:
Common types and objects used in many other Rimbu packages
37 lines (36 loc) • 1.11 kB
text/typescript
/**
* Throws an `ErrBase.ForcedError` error when called.
* @example
* ```ts
* const emptyMap = HashMap.empty<number, string>()
* emptyMap.get(5, Err);
* // throws: ErrBase.ForcedError(message: 'Err: Forced to throw error')
* ```
*/
export declare function Err(): never;
export declare namespace ErrBase {
/**
* A custom error instance.
*/
abstract class CustomError {
readonly message: string;
constructor(message: string);
get name(): string;
}
/**
* Error type that is thrown by `Err` and the functions returned by `ErrBase.msg`.
*/
class ForcedError extends CustomError {
}
/**
* 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: ErrBase.ForcedError(message: 'not found')
* ```
*/
function msg(message: string): () => never;
}