kaven-basic - v6.1.0
    Preparing search index...

    Function Try

    • Safely executes a function and catches any exceptions or promise rejections.

      • If the function executes successfully, its result is returned directly.
      • If it throws (synchronously) or rejects (asynchronously), the provided fallback value is returned instead.
      • If a logger is provided, any caught exception is logged using logger.Warn(error).

      Type Parameters

      • T

      Parameters

      • fn: () => T | Promise<T>

        The function to execute. Can be synchronous or return a Promise.

      • fallback: T

        The value to return if an error occurs.

      • Optionallogger: ILoggingAgent

        Optional logger that implements a Warn(error) method.

      Returns T | Promise<T>

      The function's result if successful, otherwise the fallback value.