faultyOf

inline fun <Error : Any> faultyOf(catch: (throwable: Throwable) -> Faulty<Error> = ::rethrow, block: RaiseScope<Error>.() -> Unit): Faulty<Error>

Context runner that encapsulates the result of block as a Faulty.

Note: catch will rethrow by default.

// Faulty<String>
faultyOf { "error" }

// Faulty<Throwable>
faultyOf { throw IllegalStateException("error") }

Parameters

catch

Map thrown exceptions to a Faulty. (Throws by default).

block

The code to execute.

See also


inline fun <In, Error : Any> In.faultyOf(catch: (throwable: Throwable) -> Faulty<Error> = ::rethrow, block: RaiseScope<Error>.(In) -> Unit): Faulty<Error>

Context runner that encapsulates the result of block as a Faulty.

Note: catch will rethrow by default.

// Faulty<String>
"value".faultyOf { it.uppercase() }

// Faulty<Throwable>
3.faultyOf { throw IllegalStateException("error") }

Receiver

Some input type, In, passed to block.

Parameters

Error

The error type of the Faulty, which must be a subtype of Any.

catch

Map thrown exceptions to a Faulty. (Throws by default).

block

The code to execute.

See also