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