tryRecoverOf

inline suspend fun <Ok, ErrorIn, ErrorOut> Outcome<Ok, ErrorIn>.tryRecoverOf(catch: (throwable: Throwable) -> Outcome<Ok, ErrorOut> = ::rethrow, scope: RaiseScope<ErrorOut> = DefaultRaiseScope(), failure: RaiseScope<ErrorOut>.(ErrorIn) -> Ok): Outcome<Ok, ErrorOut>

Transforms a Failure into a Success, wrapping the result with outcomeOf error-catching semantics.

This is the outcomeOf alternative to recover — it catches exceptions rather than letting them propagate.

outcomeOf { 4 }                              // Success(4)
.tryRecoverOf { Unit } // No change — Success(4)
.andThenOf { throw FileNotFoundException("test") } // Failure(FileNotFoundException("test"))
.tryRecoverOf { 7 } // Success(7)

Parameters

Ok

The Success value type.

ErrorIn

The incoming Failure error type.

ErrorOut

The outgoing Failure error type after transformation.

catch

Handles exceptions thrown by failure. Defaults to rethrowing via rethrow.

scope

The RaiseScope used to raise typed errors.

failure

The transform applied to the Failure error value.

See also