Try
Keywords: net.corda.core.utilities.Try class
Date: 2023-09-18

net.corda.core.utilities

## Class Try<A>

- net.corda.core.utilities.Try<A>

- Direct Known Subclasses:
    Try.Failure, Try.Success

      public class Try<A>

  Representation of an operation that has either succeeded with a result (represented by `class Try.Success`) or failed with an exception (represented by `class Try.Failure`).

  See Also:
    `class Try.Success`, `class Try.Failure`

- - ### Field Detail

    - #### Companion

          public static net.corda.core.utilities.Try.Companion Companion

  - ### Method Detail

    - #### isFailure

          public boolean isFailure()

      Returns `true` iff the `class Try` is a `class Try.Success`.

      See Also:
        `class Try`, `class Try.Success`

    - #### isSuccess

          public boolean isSuccess()

      Returns `true` iff the `class Try` is a `class Try.Failure`.

      See Also:
        `class Try`, `class Try.Failure`

    - #### getOrThrow

          public A getOrThrow()

      Returns the value if a `class Try.Success` otherwise throws the exception if a `class Try.Failure`.

      See Also:
        `class Try.Success`, `class Try.Failure`

    - #### throwError

          @NotNull
          public Try<A> throwError()

      If this is a `class Try.Failure` wrapping an Error then throw it, otherwise return `this` for chaining.

      See Also:
        `class Try.Failure`, Error

    - #### map

          @NotNull
          public <B> Try<B> map(@NotNull
                                         kotlin.jvm.functions.Function1<? super A,? extends B> function)

      Maps the given function to the value from this `class Try.Success`, or returns `this` if this is a `class Try.Failure`.

      See Also:
        `class Try.Success`, `class Try.Failure`

    - #### flatMap

          @NotNull
          public <B> Try<B> flatMap(@NotNull
                                             kotlin.jvm.functions.Function1<? super A,? extends net.corda.core.utilities.Try<? extends B>> function)

      Returns the given function applied to the value from this `class Try.Success`, or returns `this` if this is a `class Try.Failure`.

      See Also:
        `class Try.Success`, `class Try.Failure`

    - #### combine

          @NotNull
          public <B,C> Try<C> combine(@NotNull
                                               Try<? extends B> other,
                                               @NotNull
                                               kotlin.jvm.functions.Function2<? super A,? super B,? extends C> function)

      Maps the given function to the values from this `class Try.Success` and `other`, or returns `this` if this is a `class Try.Failure` or `other` if `other` is a `class Try.Failure`.

      See Also:
        `class Try.Success`, `other`, `class Try.Failure`, `other`, `other`, `class Try.Failure`

    - #### doOnSuccess

          @NotNull
          public Try<A> doOnSuccess(@NotNull
                                             java.util.function.Consumer<? super A> action)

      Applies the given action to the value if `class Try.Success`, or does nothing if `class Try.Failure`. Returns `this` for chaining.

      See Also:
        `class Try.Success`, `class Try.Failure`

    - #### doOnFailure

          @NotNull
          public Try<A> doOnFailure(@NotNull
                                             java.util.function.Consumer<java.lang.Throwable> action)

      Applies the given action to the error if `class Try.Failure`, or does nothing if `class Try.Success`. Returns `this` for chaining.

      See Also:
        `class Try.Failure`, `class Try.Success`

    - #### on

          @JvmStatic
           @NotNull
          public static <T> Try<T> on(@NotNull
                                                           kotlin.jvm.functions.Function0<? extends T> body)

      Executes the given block of code and returns a `class Try.Success` capturing the result, or a `class Try.Failure` if a Throwable is thrown.

      It is recommended this be chained with `throwError` to ensure critial Errors are thrown and not captured.

      See Also:
        `class Try.Success`, `class Try.Failure`, Throwable, `throwError`, Error