``` import kotlinx.coroutines.* val job: Job = Jo...
# coroutines
p
Copy code
import kotlinx.coroutines.*

val job: Job = Job()
val scope = CoroutineScope(Dispatchers.Default + job)

fun throwsAsync(): Deferred<Unit> = scope.async {
  throw Exception()
}

fun loadData() = scope.launch {
  throwsAsync().await()
}

suspend fun main() {
  loadData().join()
  scope.launch { println("worked") }.join()
  joinAll()
  println("done")
}
Why doesn't this crash?
m
I think it's because
launch
is a fire&forget type of coroutine builder. The caller is not expected to handle errors. You need to register a
CoroutineExceptionHandler
on it: https://kotlinlang.org/docs/reference/coroutines/exception-handling.html#coroutineexceptionhandler
async().await()
however, will throw when you do
await()
.