Error propagation moves an uncaught exception from the coroutine where it occurs to its parent, making that parent responsible for handling it. section 18.1
An async exception reaches await
A coroutine created with async can throw an UnsupportedOperationException. Calling await() rethrows that exception so a surrounding try/catch can handle it, while the original failure is also observed by the parent coroutine. With launch, placing the try/catch inside the child handles the exception; placing it around launch does not. section 18.1
Listing 18.1 An async coroutine that throws an exception
import kotlinx.coroutines.*
fun main(): Unit = runBlocking {
val myDeferredInt: Deferred<Int> = async {
throw UnsupportedOperationException("Ouch!")
}
try {
val i: Int = myDeferredInt.await()
println(i)
} catch (u: UnsupportedOperationException) {
println("Handled: $u")
}
}
Use the runnable async example to trace exception creation, await(), and handling in sequence. section 18.1



