corda / net.corda.core.utilities / Try

Try

sealed class Try<out A>

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

Types

Failure

data class Failure<out A> : Try<A>

Success

data class Success<out A> : Try<A>

Properties

isFailure

Returns true iff the Try is a Success.

abstract val isFailure: Boolean

isSuccess

Returns true iff the Try is a Failure.

abstract val isSuccess: Boolean

Functions

combine

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

fun <B, C> combine(other: Try<B>, function: (A, B) -> C): Try<C>

doOnFailure

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

fun doOnFailure(action: Consumer<Throwable>): Try<A>

doOnSuccess

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

fun doOnSuccess(action: Consumer<in A>): Try<A>

flatMap

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

fun <B> flatMap(function: (A) -> Try<B>): Try<B>

getOrThrow

Returns the value if a Success otherwise throws the exception if a Failure.

abstract fun getOrThrow(): A

map

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

fun <B> map(function: (A) -> B): Try<B>

throwError

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

fun throwError(): Try<A>

Companion Object Functions

on

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

fun <T> on(body: () -> T): Try<T>