Created
January 30, 2021 17:47
-
-
Save GauravChaddha1996/b7575d308d5f5ecb71564f590eac1e87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runBlocking { | |
val ceh = CoroutineExceptionHandler { _, throwable -> | |
println("Failure with ${throwable.localizedMessage}") | |
} | |
val scope = CoroutineScope(SupervisorJob()+Dispatchers.IO+ceh) | |
val j = scope.launch { | |
val c1 = scope.launch { | |
throw Exception("Exception1") | |
} | |
val c2 = scope.launch { | |
delay(100) | |
println("C2 still executing") | |
} | |
joinAll(c1, c2) | |
} | |
j.join() | |
} | |
Output: | |
Failure with Exception1 | |
C2 still executing | |
Output if SupervisorJob isn't used: | |
Failure with Exception1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment