It's an Android app, I'm doing some async network ...
# coroutines
It's an Android app, I'm doing some async network requests and then I'm manipulation the UI. The network requests can throw `IOException`s or `HttpException`s so I need to catch them, otherwise the app will crash.
Some you can catch just `IOException`s, can't you?
, at least (multi catch would be useful)
but I'm also catching other exceptions and submit them to my crash reporting instead of letting the app crash
And how do you handle your IOExceptions? Like some specific code everywhere, so you’ve encapsulated the way you handle IOExceptions into some common code?
I have some generic retry logic for the httprequests (I'm using Rx for this) but if it fails after n times, I just swallow it and set the UI to some fail state
@elizarov so
if (e is CancellationException) throw e
is ok in my catch block?
I see thanks. Yes, it is Ok. You can also have the same line in your crash reporter.
ok, thanks for help. do you think there is a way, to streamline this?
I would extract into some some common code. Actually, I’d install a crash reporter as
CoroutineExceptionHandler in my context and make it ignore
, but report everything else
but where do I put the UI code then?
Basically, the idea is that instead of doing
launch(UI) { … }
to start a coroutine you do
luanch(myOwnContext) { … }
, where
myOwnContext = UI + myExceptionHandler
👍 1
@kirillrakhman How do you deal with this?
@cbruegg currently I don't
i.e. I have automatic cancelation based on Navi, but I don't check the lifecycle after every suspension point
@elizarov I understand, but I still need to know when the coroutine fails, so I need to extend my exception logger context and provide that?
It is hard to get a more specific advice without looking at your actual code
Are you sure though your jobs are actually canceled even when they're already in the Handler queue? (If you don't know what I mean and have the time, feel free check out the example project I've linked to)