Skip to content

Variable.fromThrowable

GitHub Actions edited this page May 22, 2025 · 1 revision

resultar / fromThrowable

Variable: fromThrowable()

const fromThrowable: <Fn, E>(fn, errorFn?) => (...args) => Result<ReturnType<Fn>, E> = Result.fromThrowable

Defined in: result.ts:628

Wraps a function with a try catch, creating a new function with the same arguments but returning Ok if successful, Err if the function throws

Type Parameters

Fn

Fn extends (...args) => unknown

E

E

Parameters

fn

Fn

function to wrap with ok on success or err on failure

errorFn?

(e) => E

when an error is thrown, this will wrap the error result if provided

Returns

(...args): Result<ReturnType<Fn>, E>

Parameters

args

...Parameters<Fn>

Returns

Result<ReturnType<Fn>, E>

Clone this wiki locally