Maciek
12/22/2021, 2:09 PMcatch { }
in the chain? If I'd want to have a infinite flow I must handle the exceptions with try catch
in the lambdas because flow will close after any exception "leaking" to the stream, right? Or is there a way to do some explicit recovery from the exception? Example code: only 0
will be emitted, next emit 1
is never executed due to flow completion after exception.
flow {
emit(0)
emit(1) // never executed
}
.onEach { if (it == 0) throw Throwable() }
.catch { println(it) } // catch and ignore
.collect()
Maciek
12/22/2021, 2:09 PMtry catch
inside onEach
Adam Powell
12/22/2021, 4:51 PMemit(0)
threw the exception. The .catch {}
operator surrounds the call to collect for its source, so the position of execution in the source flow is already gone by the time the catch operator's block runsMaciek
12/22/2021, 4:58 PMMaciek
12/22/2021, 4:59 PMAdam Powell
12/22/2021, 5:05 PMMaciek
12/22/2021, 5:16 PMAdam Powell
12/22/2021, 5:42 PMAdam Powell
12/22/2021, 5:43 PM