https://kotlinlang.org logo
Title
d

davide

10/22/2019, 3:04 PM
Hi all, I'm playing with Flow and error handling. I'm doing somethink like: (1..5).asFlow().onEach{ //throw error }.retryWhen { c, a -> ... } But the flow restarts from the beginning. What is the best way to skip the emitted element that cause the error and restart from the next one?
s

streetsofboston

10/22/2019, 3:08 PM
Flows, like Observable/Flowables in Rx, terminate/complete when an error occurs. You cannot resume the upstream Flow/Observable. At best you can return a non-error value, but the Flow/Observable still terminates, or you can restart the upstream Flow/Observable entirely (it basically will re-collect/re-subscribe).
d

davide

10/22/2019, 3:10 PM
ok, so the only way may we using catch method with emitAll on a new flux that starts from the next element
(thanks for the answer)
s

streetsofboston

10/22/2019, 3:12 PM
Yup, or add a
try {.... } catch { ....}
inside your
.onEach
d

davide

10/22/2019, 3:20 PM
yes, more simple 🙂