Skip to content

Instantly share code, notes, and snippets.

@adesamp
Created July 7, 2021 11:44
Show Gist options
  • Save adesamp/b4861c320bec93e7ad93be2865185e28 to your computer and use it in GitHub Desktop.
Save adesamp/b4861c320bec93e7ad93be2865185e28 to your computer and use it in GitHub Desktop.
ExceptionHandlingWithLaunch.kt
private val exceptionHandling = CoroutineExceptionHandler { coroutineContext, throwable ->
print("got error: ${throwable.message}")
}
@Test
fun `exception with handling in launch with scope`() {
runBlocking {
val job = GlobalScope.launch(exceptionHandling) {
println("start job")
throw IllegalArgumentException("throw IllegalArgumentException from launch")
}
job.join()
println("finish")
}
}
// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment