catch

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

Executes block inside the current RaiseScope, converting any thrown Throwable — including fatal kotlin.Error subclasses — to a raised Error via catch.

Warning: CancellationException is not propagated. Use catching in suspend contexts.

It is YOUR responsibility to use catch to handle fatal kotlin.Error cases appropriately!

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

Return

The result of block on success.

Parameters

catch

Converts a caught Throwable to an Error. Re-throws by default.

block

The block to execute.

See also

Throws

If catch re-throws.