RaiseScope

sealed interface RaiseScope<in Error : Any>

A scope for raising errors.

Use default context runner to create a new RaiseScope. Within the scope, the raise method can be called to throw any Error as if it were a Throwable and in doing so, short-circuit the scope execution.

See also

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Functions

Link copied to clipboard
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.

Link copied to clipboard
abstract fun complete()

Completes the scope, preventing any further errors from being raised.

Link copied to clipboard
inline fun <Error : Any> RaiseScope<Error>.ensure(condition: Boolean, raise: () -> Error)

Ensures that the given condition is true, otherwise raises an Error.

Link copied to clipboard
inline fun <Ok : Any, Error : Any> RaiseScope<Error>.ensureNotNull(value: Ok?, raise: () -> Error): Ok

Ensures that the given value is not null, otherwise raises an Error.

Link copied to clipboard
inline fun <In : Any, Out : Any, Error : Any> RaiseScope<Error>.fold(block: (scope: RaiseScope<Error>) -> In, catch: (throwable: Throwable) -> Out = ::rethrow, recover: (error: Error) -> Out, transform: (value: In) -> Out): Out
Link copied to clipboard
inline fun <Error : Any> RaiseScope<Error>.raise(error: () -> Error): Nothing

Invokes error, wraps it as a Throwable and then throws it, short-circuiting the RaiseScope execution.

Link copied to clipboard
abstract fun raised(error: Error): Nothing

Wraps raised as a Throwable and throws it, short-circuiting the RaiseScope execution.