utils/tryCatch
Esta página aún no está disponible en tu idioma.
Functions
Section titled “Functions”tryCatch()
Section titled “tryCatch()”Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T
E
= Error
Parameters
Section titled “Parameters”() => T
| Promise
<T
>
The function to execute, which can be a promise or a synchronous function.
Returns
Section titled “Returns”Promise
<Result
<T
, E
>>
A promise that resolves to a tuple containing the result and error.
Call Signature
Section titled “Call Signature”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).
Type Parameters
Section titled “Type Parameters”T
E
= Error
Parameters
Section titled “Parameters”Promise
<T
>
Returns
Section titled “Returns”Promise
<Result
<T
, E
>>
A promise that resolves to a tuple containing the result and error.