As asked
Explain structured concurrency in Kotlin. If a coroutine inside a CoroutineScope throws an exception, what exactly happens to its sibling coroutines and the parent scope? How does CancellationException differ from other exceptions in this propagation model?
Sample answer outline
The answer should cover how a child failure cancels the parent scope and all sibling coroutines unless SupervisorScope or SupervisorJob is used. CancellationException is treated specially, it cancels but does not propagate as a failure to the parent. The candidate should distinguish between Job and SupervisorJob and know that launch and async handle exceptions differently.
Expect these follow-ups
- When would you use supervisorScope vs CoroutineScope?
- If async throws, when exactly does the exception surface?