Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GauravChaddha1996/b7575d308d5f5ecb71564f590eac1e87 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/b7575d308d5f5ecb71564f590eac1e87 to your computer and use it in GitHub Desktop.
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