Class Try<T>

An inline try/catch statement class

Type Parameters

  • T

Hierarchy

  • Try

Constructors

Properties

Methods

Constructors

  • Instantiate the class

    Type Parameters

    • T

    Parameters

    • tryFn: (() => T)

      Function to try running which may throw an error

        • (): T
        • Returns T

    Returns Try<T>

Properties

#error?: any
#returnValue?: T
#state: "error" | "success"

Methods

  • Catch a specific error instance

    Returns

    Type Parameters

    • E extends (new (...args: any) => any)

    Parameters

    • type: E

      The error type to catch

    • catchFn: ((e: InstanceType<E>) => T)

      Function to return a new value if the try function threw the specified error type, which can itself throw an error to be caught

        • (e: InstanceType<E>): T
        • Parameters

          • e: InstanceType<E>

          Returns T

    Returns Try<T>

  • Catch all errors

    Returns

    Parameters

    • catchFn: ((e: any) => T)

      Function to return a new value if the try function threw any error, which can itself throw an error to be caught

        • (e: any): T
        • Parameters

          • e: any

          Returns T

    Returns Try<T>

  • Get the final value returned by the try or catch functions

    Returns

    Throws

    Will throw any error that has not been caught

    Parameters

    • Optional finallyFn: (() => void)

      Optional function to run at the end of the of the statement

        • (): void
        • Returns void

    Returns T

Generated using TypeDoc