dave08
01/02/2019, 11:25 AMrunCatching { code() }
.onFailure {
if (it is DomainException) handleDomainError(it)
}.getOrThrow() // To throw other errors that are not domain related, if there are.
// This might be much better
runCatching { code() }
.onFailure<DomainException> { handleDomainError(it) }
.onFailure<DomainException2> { handleOtherDomainError(it) }
// If there's another error it throws here without using getOrThrow()
// this is like having multiple 'catch's in a try/catch, and is easier to compose and use with lists of results... also there's no nesting.
@karelpeeters