catching

inline suspend fun <Ok, Error> RaiseScope<Error>.catching(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.

Unlike catch, this suspend variant calls ensureActive before delegating to catch, so CancellationException is never silently swallowed. Prefer catching over catch in suspend contexts.

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

val x: Fault<String> = faultOf {
catching({ "$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 suspend block to execute.

See also

Throws

If catch re-throws.