Function catcher

  • Run the supplied arity-zero function, and if it throws an error, return the caughtValue instead (or undefined if not provided).

    This is only safe to do when we know that nothing at any point in the call stack relies on the Error.stack property, and only worth doing in hot paths where a function is expected to throw often (for example, calling statSync on many paths to find the first one that exists).

    Type Parameters

    • F extends ((...a) => any)

    Parameters

    • fn: F

    Returns FindReturnType<OverloadMap<F>, []> | undefined

  • Type Parameters

    • F extends ((...a) => any)

    • E

    Parameters

    • fn: F
    • caughtValue: E

    Returns FindReturnType<OverloadMap<F>, []> | E

Generated using TypeDoc