https://kotlinlang.org logo
#announcements
Title
# announcements
g

Greg Stepniewski

08/30/2019, 7:57 AM
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

Can Orhan

08/30/2019, 8:03 AM
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

Matej Drobnič

08/30/2019, 8:05 AM
Yeah SupervisorJob is excepton to that rule
g

Greg Stepniewski

08/30/2019, 8:05 AM
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

Can Orhan

08/30/2019, 8:15 AM
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

streetsofboston

08/30/2019, 12:13 PM
Maybe my blog post can help. “Exceptional Exceptions for Coroutines made easy…? part II: Supervision” by Anton Spaans https://link.medium.com/Wky7nyqEzZ
2 Views