Hi, I would like to execute some code that may fai...
# arrow
d
Hi, I would like to execute some code that may fail. I was about to use
Try
but it is deprecated in favour of
IO
or
Either.catch
. But: • I do not know how to use IO and it looks not appriopriate for such simple case • Either.catch requires coroutines so I ended up with following function:
Copy code
fun <R> attempt(f: suspend () -> R): Either<Throwable, R> = runBlocking { Either.catch { f() } }
Is there any better way to: • call some code • catch possible exception • convert it to Either<Error, Result>?