If I get an exception for a coroutine scope, it’s ...
# coroutines
e
If I get an exception for a coroutine scope, it’s marked as canceled even with a handler. What is the best practice to make another call with that scope? since it’s marked canceled my instinct is to create a new one, is that the preferred approach? I thought the handler would ensure it was not canceled, which doesn’t seem to be the case.
Copy code
try {
    ...
} finally {
    withContext(NonCancellable) {
        // can suspend even after cancellation
    }
}
e
I did something like:
Copy code
scope.launch(exceptionHandler) {
}
However, once an exception happens, the scope cannot be used again. One solution is to add a try-catch inside of the
launch{}
but I might just not understand how
Copy code
CoroutineExceptionHandler
is intended to work
s
CoroutineExceptionHandler
happens after the coroutine has completed. It doesn't let you recover from the exception. https://kotlinlang.org/docs/exception-handling.html#coroutineexceptionhandler
e
ah! yeah, that helps explain the situation then 🙂 Thanks for pointing that out!
i
You can run your coroutines inside SupervisorJob. It doesn't cancel if one of its children cancel