how to handle exceptions while using `Flow`? I was...
# coroutines
i
how to handle exceptions while using
Flow
? I was looking at the
onErrorCollect
and
onErrorReturn
but I'm not sure how to use it. I'm using the simple
try-catch
now, but I was wondering if it already has an API for that. My usecase is that I'm trying to write an offline-first approach: I first search on local storage and emit what it has, then I look online and emit the itens that aren't cached yet . I want to handle the exceptions (mostly networking ones) only if the local storage was empty in the first place.
l
I read the documentation the other day, and it was written in it. It's not too wide so I definitely recommend to check it out, and then, look at the operators documentation only when you need it. The doc is already in your IDE with the sources 😉
i
you mean this?
Copy code
/**
 * Switches to the [fallback] flow if the original flow throws an exception that matches the [predicate].
 */
Maybe I'm too newbie, but I'm not sure why it receives the fallback flow. haha I like when it has examples that I can test and see what happens. (Sure, I should try to write one...)
l
Hum, I don't think I read this part of the documention, but it definitely seems to be worth improvements. If you think the same, I think you should open an issue on GitHub to track this, and ask for what you think would improve understanding (e.g. an example, as you mentioned).
You can also try for yourself and contribute, of course, especially considering this is a preview API, but reporting it is already a good thing and is likely to be helpful
i
Yeah, you are right. I'll try to open the issue later. If this isn't the documentation you was mentioning, maybe you could send me the one you was referring? Thanks in advance 😃
l
I was referring to
flow
,
collect
,
flowIn
, flowOn`,
flowInChannel
, and that's all I have on the top of my head. I concluded I do not need
Flow
in my apps yet, because `Channel`s and plain suspend functions currently satisfy all my needs. That will probably change when `SQLDelight gets
Flow
support though.
i
oh, I see. I'm using it for testing and learning purposes, that's why I'm trying to implement this use case (it's common while using rxjava). 🙂