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

abstract val isFailure: Boolean

Returns true iff the Try is a Success.

isSuccess

abstract val isSuccess: Boolean

Returns true iff the Try is a Failure.

Functions

combine

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

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.

flatMap

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

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

getOrThrow

abstract fun getOrThrow(): A

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

map

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

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

Companion Object Functions

on

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

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

Extension Functions

contextLogger

fun Any.contextLogger(): Logger

When called from a companion object, returns the logger for the enclosing class.

Inheritors

Failure

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

Success

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