Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val eh = CoroutineExceptionHandler { _, throwable ->
println("Oops error occured: ${throwable.localizedMessage}")
}
// Crashes the main thread since top most launch doesn't
// handle exception even if child coroutine does
launch {
delay(100)
launch(eh) {
throw Exception("I failed")
}
}
// Doesn't crashes the main thread and the exception is caught
launch(eh) {
delay(100)
launch {
throw Exception("I failed")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment