Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/dtils/errors.ts>bindErrorRecovery

The best unofficial library of utilities for Deno applications
Go to Latest
function bindErrorRecovery
import { bindErrorRecovery } from "https://deno.land/x/dtils@2.6.0/errors.ts";

Bind error recovery to fn, which is expected to be a function. If when the function is later called and errors, recoverWith will be returned instead.

Examples:

function foo() {
	throw new Error('I throw')
}

const safeFoo = bindErrorRecovery(foo, null)

foo() // Error: I throw
safeFoo() // null

Type Parameters

Args extends unknown[]
Return extends unknown
O

Parameters

fn: (...args: Args) => Return
recoverWith: O

Returns

(...args: Args) => Return | O