Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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