Going through the Coroutines documentation (<https...
# announcements
g
Going through the Coroutines documentation (https://kotlinlang.org/docs/reference/coroutines/exception-handling.html) and I found this:
If a coroutine encounters exception other than CancellationException, it cancels its parent with that exception. This behaviour cannot be overridden and is used to provide stable coroutines hierarchies for structured concurrency.
However, you have SupervisorJob which says
A failure or cancellation of a child does not cause the supervisor job to fail and does not affect its other children.
These two seem to contradict, since SupervisorJob clearly overrides the behaviour of children cancelling their parent on failure - or am I missing something?
c
The doc for
Job
does, however, make this distinction explicit
Copy code
By default, a failure of any of the job's children leads to an immediate failure of its parent and cancellation of the rest of its children. This behavior can be customized using SupervisorJob.
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-job/index.html
m
Yeah SupervisorJob is excepton to that rule
g
Does that mean the segment in "Exception Handling" is wrong? I wanted to quote it in a presentation, but it seems like I should quote the doc for Job instead?
c
Well I wouldn’t go as far as calling it wrong since the same page has a section on
SupervisorJob
In other words, the page as a whole seems correct & complete (to the best of my knowledge)
s
Maybe my blog post can help. “Exceptional Exceptions for Coroutines made easy…? part II: Supervision” by Anton Spaans https://link.medium.com/Wky7nyqEzZ