pavankumar
05/11/2020, 8:02 AMfun main() = runBlocking {
with(CoroutineScope(coroutineContext + CoroutineExceptionHandler { _, _ -> println("Exception")})) {
val firstChild = launch() { // if i add "CoroutineExceptionHandler here, then launch coroutine will handle exception without printing on console
println("First child is failing")
delay(1000)
throw AssertionError("First child is cancelled")
}
// launch the second child
val secondChild = launch {
println("First child is cancelled: ${firstChild.isCancelled}, but second one is still active")
try {
delay(Long.MAX_VALUE)
} finally {
println("Second child is cancelled")
}
}
secondChild.join()
}
}