Why Exception Handling with Kotlin Coroutines is hard and how to master it
summary
Kotlin coroutines propagate unhandled exceptions up the job hierarchy, so installing a CoroutineExceptionHandler on a child coroutine does nothing — it must live on the root or scope context; handlers can log but cannot recover because the coroutine already completed exceptionally. launch failures surface immediately, async failures encapsulates exceptions in Deferred and rethrow on await, coroutineScope rethrows child exceptions to callers, supervisorScope isolates siblings, and always rethrow CancellationException or cancellation will be swallowed and work continues unexpectedly.
AI-written summary · about
chapters (13)
- 0:00Introduction to talk
- 1:18Basics of exceptions
- 3:06Exceptions in coroutines
- 4:35Why try-catch fails in coroutines
- 7:47Coroutine exception handlers
- 11:39Try-catch vs exception handlers
- 14:08Cancellation and try-catch
- 20:38Launch vs async exceptions
- 23:27Async child coroutines
- 25:17Coroutine scope scoping
- 27:05Supervisor scope explained
- 29:35Five key takeaways
- 32:31Q&A session
related talks
42mWhy exception handling with Kotlin Coroutines is hard and how to master it!
42mWhy exception handling with Kotlin Coroutines is so hard, how to master it!
37mCoroutines! Gotta catch 'em all!
43mTough Questions About Kotlin Coroutines
37mPractical Patterns for Kotlin Coroutines in Production
44mTesting Kotlin Coroutines
47mKotlin Coroutines
45mAll the Pitfalls of Coroutines
