try Recover
inline fun <Ok, ErrorIn, ErrorOut> Outcome<Ok, ErrorIn>.tryRecover(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 outcome error-catching semantics.
Success — returned unchanged.
If failure throws, the exception is re-encapsulated or re-thrown via catch.
This is the outcome (non-suspend) alternative to recover — it catches exceptions rather than letting them propagate.
outcome { 4 } // Success(4)
.tryRecover { Unit } // No change — Success(4)
.andThen { throw FileNotFoundException("test") } // Failure(FileNotFoundException("test"))
.tryRecover { 7 } // Success(7)Content copied to clipboard
Parameters
Ok
The Success value type.
Error In
The incoming Failure error type.
Error Out
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.