Sam
04/08/2019, 12:33 AMfun main() {
val handler = CoroutineExceptionHandler { _, throwable ->
println("Exception $throwable")
}
runBlocking {
val scope = CoroutineScope( coroutineContext + handler )
scope.launch {
throw Exception()
}.join()
}
println( "main done" )
}
octylFractal
04/08/2019, 4:07 AMsupervisorJob
, child jobs propagate exceptions outwards: https://kotlinlang.org/docs/reference/coroutines/exception-handling.html#exceptions-in-supervised-coroutinesIf a coroutine encounters exception other than CancellationException, it cancels its parent with that exception. This behaviour cannot be overridden and is used to provide stable coroutines hierarchies for structured concurrency which do not depend on CoroutineExceptionHandler implementation. The original exception is handled by the parent when all its children terminate.
gildor
04/08/2019, 12:17 PMSam
04/08/2019, 1:05 PMval scope = CoroutineScope( handler )
gildor
04/08/2019, 1:25 PMSam
04/08/2019, 1:26 PMgildor
04/08/2019, 1:26 PMSam
04/08/2019, 1:28 PMval scope = CoroutineScope( Job() + handler )
gildor
04/08/2019, 1:28 PMSam
04/08/2019, 1:29 PMgildor
04/08/2019, 1:29 PMfun main() {
try {
runBlocking {
launch {
throw Exception()
}
}
} catch(throwable: Exception) {
println("Exception $throwable")
}
println( "main done" )
}
Sam
04/08/2019, 1:36 PMgildor
04/08/2019, 1:39 PMSam
04/08/2019, 2:30 PMgildor
04/08/2019, 4:42 PM