Do you wrap `delay` in try/catch so it doesn't cra...
# coroutines
e
Do you wrap
delay
in try/catch so it doesn't crash if job was cancelled while waiting?
🙀 2
😱 3
d
Hopefully not, since the entire purpose of cancellation is to stop computations from continuing! Normally, you should always rethrow a
CancellationException
if you happened to catch it.
e
We see raise of the JobCancellation exception in crashlytics
Since stacktrace is not helpful, I was looking to the code around it happened
And only things I see is
tryEmit
on channel and
delay
in view model scope
AI says to wrap delay in NonCancellable context
no red 7
d
Copy code
coroutineScope {
    val job = launch {
        delay(100.seconds)
    }
    job.cancel()
}
will not throw an exception. Coroutines don't treat cancellation exceptions as problems. Something more complex than just
delay
throwing because of a cancellation must be going on.
e
Thanks!
d
You're welcome, but we didn't really figure out what's going on. If you'd like, you could share some code so that we could brainstorm a way to restructure it.
s
Yeah, don't log any CancellationException if you have an exception handler. They are fine.
Eg, our OkHttp (Retrofit) would log these as "Cancelled" over and over again when a network request was suspending. We had to suppress those.
e
Oke people, thank you so much for guidance. So I tried to look further what happens after even fired and found one more place where runBlocking is called with another view model scope that might be cancelled
I'm checking if the scope needed there at all
r
Since stacktrace is not helpful
Taking this opportunity, I'd recommend Decoroutinator for full traces.
e
yeah, something we discussing internally
There is also some movement from JB to make it easier