You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I found something interesting to me and want to know some more educated opinion on this.
We have CoroutineScope, where there are two Coroutines A and B. Both have some independent business logic and own business exception hierarchy.
When Coroutine-B is doing some work, and Coroutine-A throws some business exception, first coroutine is cancelled by "internal" kotlinx.coroutines.JobCancellationException.
What is kind of strange is that when I get rootCause I get business exception from Coroutine-A inside try/catch block inside Coroutine-B.
This means that logs or debugging is little bit misleading.
The only reasonable explanation I have is, that by this behavior it says, that Coroutine was cancelled by particular exception and Kotlin Coroutine machinery does not care that exception is from different part of business logic - it just says the state, that it was cancelled because of that exception.
Am I right? Or Am I missing something?
If yes, than it means, that catching and/or logging kotlinx.coroutines.JobCancellationException does not make sense. And another question comes to my mind is what are proper use-cases to catch JobCancellationException in the wild?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I found something interesting to me and want to know some more educated opinion on this.
We have
CoroutineScope
, where there are two Coroutines A and B. Both have some independent business logic and own business exception hierarchy.When Coroutine-B is doing some work, and Coroutine-A throws some business exception, first coroutine is cancelled by "internal"
kotlinx.coroutines.JobCancellationException
.What is kind of strange is that when I get
rootCause
I get business exception from Coroutine-A inside try/catch block inside Coroutine-B.This means that logs or debugging is little bit misleading.
The only reasonable explanation I have is, that by this behavior it says, that Coroutine was cancelled by particular exception and Kotlin Coroutine machinery does not care that exception is from different part of business logic - it just says the state, that it was cancelled because of that exception.
Am I right? Or Am I missing something?
If yes, than it means, that catching and/or logging
kotlinx.coroutines.JobCancellationException
does not make sense. And another question comes to my mind is what are proper use-cases to catchJobCancellationException
in the wild?I also prepared small steps to reproduce repository here https://github.com/bedla/kotlin-coroutines-cancellation-jumping-exception
Thanks for explanation, or link to some documentation.
Ivos
Beta Was this translation helpful? Give feedback.
All reactions