vtry v1.0.9
vtry
tryit + verror = Verbosely try.
API
This module exports one function that can be called in several ways described below. In each case,
fis the original function that might throw.gis a proxy function that wrapsf, preserving context (this) and arguments. If no error is thrown, it forwards the result.
g = vtry(f)
Errors are silently ignored.
g = vtry(f, hnd, ...args)
In case of an error, return hnd(err, ...args).
g = vtry(f, errMsg, errOpt)
- Required prior knowledge: verror
Decorate potentially-cryptic errors with an error message errMsg that
ideally describes what operation you were trying to perform.
errMsg must be either a non-empty string or an array.
It will be used as the sprintf_args to VError.
errOpt are the options as described in VError.
Promise API
There's also a method vtry.pr ("Promise") which works almost as above,
except it takes an async function f and returns an async function g.
As a special convenience, supplying 1 (the number) as f is a shorthand
for the identity function, so you can easily pass existing promises to g.
Known issues
- Needs more/better tests and docs.
License
ISC