- By default if an exception occurs in child coroutines, the parent coroutine and all sibling coroutines are cancelled.
- You have catch the exception where it occurs, wrapping builder is useless.
- If you want parent and siblings to continue use
SupervisorJob
. Don't use this as argument to coroutine builder. - You can also wrap coroutine builders in
supervisorScope
to stop exception propagation. - In case of async/await builder wrap await in try/catch.
- If a coroutine throw a subclass on
CancellationException
, the exception will not be propagated. CoroutineExceptionHandler
is good way to catch exception if you need to handle all exception in the same way. Source