Function attemptOrCatch

  • Attempt to call a function returning either the result or an error if one occurs

    Returns

    either the result of f or an error

    Example

    attemptOrCatch(() => { throw new Error() }) // returns error
    

    Example

    attemptOrCatch(() => 'hello') === 'hello'
    

    Type Parameters

    • TErr extends Error

    • TReturn

    Parameters

    • f: (() => TReturn)

      the function to call

        • (): TReturn
        • Returns TReturn

    Returns TErr | TReturn

Generated using TypeDoc