Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:48
Show Gist options
  • Save GauravChaddha1996/68f9938519fc323ded2178e716cd1377 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/68f9938519fc323ded2178e716cd1377 to your computer and use it in GitHub Desktop.
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