Search⌘ K
AI Features

Resuming Suspension with an Exception

Explore how Kotlin coroutines handle suspension and exceptions by learning to resume coroutines with thrown exceptions. Understand the distinction between suspending functions and coroutines, how to signal network errors, avoid memory leaks, and convert callback functions into suspending functions. This lesson provides practical knowledge for managing coroutine exceptions effectively.

Every function we call might return some value or throw an exception. The same is true for suspendCoroutine. When resume is called, it returns data passed as an argument. When resumeWithException is called, the exception we pass as an argument is conceptually thrown from the suspension point. Let’s run an example ...