https://kotlinlang.org logo
#coroutines
Title
# coroutines
c

Casey Brooks

09/17/2019, 4:54 PM
Is this the proper way to detect if a coroutine has been cancelled? For context, I was trying to just catch and handle failures, and found I was catching `CancellationException`s too, and I’m not sure if this is how I should be handling it
Copy code
try {
    coroutineScope {
        next()
    }
} catch (e: Exception) {
    if(e !is CancellationException) {
        onCancelled()
    }
    else {
        onFailure()
    }
}
3 Views