Hi all, I'm playing with Flow and error handling. ...
# coroutines
d
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
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
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
Yup, or add a
try {.... } catch { ....}
inside your
.onEach
d
yes, more simple 🙂