outcome Of
Context runner that encapsulates the Ok result of block as an Success, and any raised or caught errors as an Failure.
Note: catch will rethrow by default. This is because the consumer needs to manually override the parameter and map it to an Outcome (if desired). Assigning it to Failure directly will only force Error to be interpreted as Throwable by the RaiseScope, which may interfere with the intended Error type!
// Outcome<Unit, Throwable>
outcomeOf(::Failure) { // this: RaiseScope<Throwable> -> ... }
// Outcome<Int, String>
outcomeOf { // this: RaiseScope<String> ->
raise { "error" }
return 3
}
// Outcome<String, NullPointerException>
outcomeOf { // this: RaiseScope<NullPointerException> ->
catch({ it }) { throw NullPointerException() }
}
Parameters
Map thrown exceptions to an Outcome. (Throws by default).
The code to execute.
See also
Context runner that encapsulates the result of block as an Success, and any raised or caught errors as an Failure.
Note: catch will rethrow by default. This is because the consumer needs to manually override the parameter and map it to an Outcome (if desired). Assigning it to Failure directly will only force Error to be interpreted as Throwable by the RaiseScope, which may interfere with the intended Error type!
// Outcome<Unit, Throwable>
outcomeOf(::Failure) { // this: RaiseScope<Throwable> -> ... }
// Outcome<Int, String>
3.outcomeOf { // this: RaiseScope<String>, it: Int ->
raise { "error" }
return it
}
// Outcome<String, NullPointerException>
outcomeOf { // this: RaiseScope<NullPointerException> ->
catch({ it }) { throw NullPointerException() }
}
Receiver
Parameters
Map thrown exceptions to an Outcome. (Throws by default).
The code to execute.