Page Contents
Home > @loopback/context > tryCatchFinally
tryCatchFinally() function
Try to run an action that returns a promise or a value with error and final actions to mimic try {} catch(err) {} finally {} for a value or promise.
Signature:
export declare function tryCatchFinally<T>(action: () => ValueOrPromise<T>, errorAction?: (err: unknown) => T | never, finalAction?: () => void): ValueOrPromise<T>;
Parameters
| Parameter | Type | Description |
|---|---|---|
| action | () => [ValueOrPromise](/doc/en/lb4/apidocs.context.valueorpromise.html)<T> | A function that returns a promise or a value |
| errorAction | (err: unknown) => T \| never | _(Optional)_ A function to be called once the action is rejected (synchronously or asynchronously). It must either return a new value or throw an error. |
| finalAction | () => void | _(Optional)_ A function to be called once the action is fulfilled or rejected (synchronously or asynchronously) |
Returns: