Recall & Review
beginner
What is the purpose of
try-catch blocks in Kotlin coroutines?They are used to catch and handle exceptions that occur inside a coroutine, preventing the coroutine from crashing the program.
Click to reveal answer
intermediate
How does
CoroutineExceptionHandler help in exception handling?It is a special coroutine context element that catches uncaught exceptions in coroutines and allows centralized handling of those exceptions.
Click to reveal answer
intermediate
What happens if an exception is thrown in a child coroutine launched with
launch?The exception is propagated to the parent coroutine and can cancel the parent and its other children unless handled properly.
Click to reveal answer
advanced
Why should exceptions in
async coroutines be handled differently?Because
async coroutines return a Deferred result, exceptions are thrown only when await() is called, so handling should be done around await().Click to reveal answer
advanced
What is the role of
supervisorScope in exception handling?It allows child coroutines to fail independently without cancelling their siblings or the parent, helping to isolate exceptions.
Click to reveal answer
Which coroutine builder propagates exceptions immediately to its parent?
✗ Incorrect
The
launch builder propagates exceptions immediately to its parent coroutine.Where should you handle exceptions when using
async coroutines?✗ Incorrect
Exceptions in
async coroutines are thrown when await() is called, so handling should be done there.What does
CoroutineExceptionHandler NOT catch?✗ Incorrect
CoroutineExceptionHandler does not catch exceptions in async coroutines before await() is called.What is the effect of using
supervisorScope?✗ Incorrect
supervisorScope lets child coroutines fail without cancelling siblings or the parent.Which statement about exception handling in coroutines is TRUE?
✗ Incorrect
Exceptions in
launch coroutines are propagated immediately to the parent.Explain how exception handling differs between
launch and async coroutines in Kotlin.Think about when exceptions become visible in each coroutine builder.
You got /4 concepts.
Describe the purpose and benefits of using
supervisorScope for exception handling in coroutines.Consider how failures affect other coroutines inside the scope.
You got /4 concepts.