https://kotlinlang.org logo
Title
s

Sam

03/07/2023, 11:11 PM
I don't remember there being two
CancellationExceptions
... They're not aliases of each other... Does either one work?
I guess my actual question is how I can have a coroutine cancel itself. I was thinking to just
throw CancellationException(...)
, but it looks like
coroutineContext.cancel(...); ensureActive()
might be more correct?
t

Trevor Stone

03/08/2023, 12:26 AM
yes calling cancel is the correct way
s

Sam

03/08/2023, 12:26 AM
Okay, cool, thanks
It still would be useful to know why there are two exception classes though... It does come up when trying to exclude
CancellationException
from a catch block (I guess I could check for both).
t

Trevor Stone

03/08/2023, 12:28 AM
On the JVM they are both typealias of java.util.concurrent.CancellationException I believe
one is from the kotlin stdlib
the other is from kotlinx.coroutines
s

Sam

03/08/2023, 12:50 AM
Ah, gotcha. I figured it might be like that. Thanks!