fault
inline fun <Error> fault(catch: (Exception) -> Fault<Error> = ::rethrow, scope: RaiseScope<Error> = DefaultRaiseScope(), block: RaiseScope<Error>.() -> Unit): Fault<Error>
Runs block inside a RaiseScope and returns a Fault.
The success value is always Unit; use raise to short-circuit with an Error.
Warning: Does not propagate kotlinx.coroutines.CancellationException — use faultOf in suspend contexts.
// Fault<String> — raises an error
val f: Fault<String> = fault { raise { "something went wrong" } }
// Fault<Exception> — exception mapped via catch
val g: Fault<Exception> = fault(catch = ::Failure) {
throw IllegalStateException("oops")
}Content copied to clipboard
Parameters
block
The block to execute within the scope.