Function tryCatching

  • Execute a block of code, catching any errors of the specified types and returning them as Err.

    If no errors are specified, the block will be executed as if it were passed to trying.

    Type Parameters

    • T
    • E extends Error

    Parameters

    • errors: ErrorClass[]

      The expected error types to catch from the block.

    • block: (() => T)

      The block of code to execute.

        • (): T
        • Returns T

    Returns Result<T, E>

    The result of the block wrapped in an Ok, or an Err containing any error thrown by the block.