catch

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

A context runner use inside the RaiseScope when you wish to catch an expected (non-fatal) Throwable and convert it to an Error from your domain.

val x: Faulty<String> = faultyOf {
catch({ "$it" }) { throw IOException() } // raises "IOException"
}

Return

The result of the block of code.

Parameters

catch

A function that converts a Throwable to an Error. Re-throws by default.

block

The block of code to execute.

Throws

If the block of code throws (provided catch maps Throwable to Error).

if catch re-throws.