A higher-order function that wraps the provided function with a try-catch block. It catches any errors that occur during the execution of the function and handles them according to the specified configuration.

  • Type Parameters

    • T extends (...args: A) => any

      The type of the function being wrapped

    • A extends any[]

      An array of arguments that the function accepts

    • V extends unknown

      The type of the value returned by the function

    Parameters

    • run: T

      The function to be wrapped

    • Optionalconfig: Partial<IConfig>

      The configuration object

      • fallback

        The fallback function to be called with the caught error (optional)

      • defaultValue

        The default value to be returned if an error occurs (optional, default: null)

    Returns (...args: A) => null | ReturnType<T>

    • The wrapped function that handles errors and returns the result or the default value