This project is part of the @thi.ng/umbrella monorepo.
Custom error types (extending Error
) and helper functions used by most
other packages in this repo.
Additional error types can be defined using
defError()
yarn add @thi.ng/errors
None
import * as err from "@thi.ng/errors";
err.illegalArity(3)
// Error: illegal arity: 3
err.illegalArgs("expected foo");
// Error: illegal argument(s): expected foo
err.illegalState("oops");
// Error: illegal state: oops
err.unsupported("TODO not yet implemented")
// Error: unsupported operation: TODO not yet implemented
// define custom error
const MyError = err.defError(
() => "Eeek... ",
(x) => x + " is not allowed!"
);
try {
throw new MyError(23);
} catch(e) {
console.warn(e.message);
console.log(e instanceof Error);
}
// Eeek... 23 is not allowed!
// true
- Karsten Schmidt
© 2018 Karsten Schmidt // Apache Software License 2.0