Erik
05/18/2020, 2:58 PMJob documentation (https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html):
Normal cancellation of a job is distinguished from its failure by the type of its cancellation exception cause. If the cause of cancellation is CancellationException, then the job is considered to be cancelled normally. This usually happens when cancel is invoked without additional parameters. If the cause of cancellation is a different exception, then the job is considered to have failed. This usually happens when the code of the job encounters some problem and throws an exception.From the first sentence I conclude that a coroutine's
CancellationException may have a cause. From the second sentence I conclude that the cause may be yet another CancellationException, 😕 am I right? And from the fourth sentence I conclude that, if failed, I will receive a CancellationException with a cause that is not a CancellationException, am I right?
So: normally, can a CancellationException have another CancellationException as its cause? If so, can this lead to deep nesting of CancellationException instances? And, if so, should traverse this chain of cancellation exceptions in search for a different type of exception to determine if this was a failure or normal cancellation?Zach Klippenstein (he/him) [MOD]
05/18/2020, 3:22 PMgenerateSequence(e){ it.cause }
.firstOrNull{ it !is CancellationException }Erik
05/18/2020, 3:37 PMCancellationException being caught?
I tried creating an example, but I only was able to catch `CancellationException`s without CancellationException causes.Zach Klippenstein (he/him) [MOD]
05/18/2020, 3:55 PMcancel(CancellationException("Oops", cause)) where cause is any other type of exception.Erik
05/18/2020, 3:59 PMCancellationException, but that's not what I normally do. Do you have an example where this would normally occur?Erik
05/18/2020, 4:02 PMCancellationException. So does this actually happen if you don't manually nest `CancellationException`s in one another?Fatih
05/18/2020, 6:06 PMErik
05/18/2020, 6:08 PMErik
05/18/2020, 6:22 PMelizarov
05/19/2020, 6:58 AMErik
05/19/2020, 7:01 AMelizarov
05/19/2020, 8:03 AMErik
05/19/2020, 8:37 AM