MCPcopy Create free account
hub / github.com/node-modules/utility / tryCatch

Function tryCatch

src/optimize.ts:4–22  ·  view source on GitHub ↗
(fn: () => T)

Source from the content-addressed store, hash-verified

2 * optimize try catch
3 */
4export function tryCatch<T = any>(fn: () => T) {
5 const res: {
6 error: Error | undefined,
7 value: T | undefined,
8 } = {
9 error: undefined,
10 value: undefined,
11 };
12
13 try {
14 res.value = fn();
15 } catch (err) {
16 res.error = err instanceof Error
17 ? err
18 : new Error(err as string);
19 }
20
21 return res;
22}
23
24/**
25 * @description Deal with typescript

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…