Saltearse al contenido

utils/tryCatch

Esta página aún no está disponible en tu idioma.

function tryCatch<T, E>(fn: () => T | Promise<T>): Promise<Result<T, E>>

Defined in: utils/tryCatch.ts:11^

A utility function that wraps a promise or a synchronous function call in a try-catch block. It returns a tuple where the first element is the result (or null if an error occurred) and the second element is the error (or null if no error occurred).

T

E = Error

() => T | Promise<T>

The function to execute, which can be a promise or a synchronous function.

Promise<Result<T, E>>

A promise that resolves to a tuple containing the result and error.

function tryCatch<T, E>(value: Promise<T>): Promise<Result<T, E>>

Defined in: utils/tryCatch.ts:12^

A utility function that wraps a promise or a synchronous function call in a try-catch block. It returns a tuple where the first element is the result (or null if an error occurred) and the second element is the error (or null if no error occurred).

T

E = Error

Promise<T>

Promise<Result<T, E>>

A promise that resolves to a tuple containing the result and error.