It seems like `CoroutineExceptionHandler`s are ignored for exceptions thrown from a coroutine `launch`ed with a parent
Job
from a
runBlocking
scope. Changing the dispatcher doesn’t seem to matter, and coroutines `launch`ed from
GlobalScope
execute the handler as I’d expect. I can’t see any documentation about this or figure out how this makes sense.
E.g.
fun main(args: Array<String>) {
val handler = CoroutineExceptionHandler { _, exception ->
println("Caught $exception")
}
runBlocking(handler) {
val job = launch {
// This exception is thrown from runBlocking, and not seen by handler.
throw AssertionError()
}
job.join()
}
}
If you change that to the following,
handler
gets run:
runBlocking {
val job = GlobalScope.launch(handler) {
Is this behavior by design?