ghedeon
01/15/2019, 9:13 AM@Test
fun `Channel exception error handler`() {
val errorHandler = CoroutineExceptionHandler { _, throwable ->
assertThat(throwable.message).isEqualTo("Failure")
}
runBlocking(errorHandler) {
val channel = produce<Nothing> { close(Exception("Failure")) }
channel.consumeEach { println() }
}
}bdawg.io
01/15/2019, 2:54 PMthrow Exception("Failure"). iirc the exception handler is used for uncaught exceptionselizarov
01/15/2019, 3:29 PMrunBlocking propagates it outside. Exception handler only “catches” exceptions that would have been lost otherwise (e.g. from a globally-scoped launch)groostav
01/16/2019, 7:03 PMlaunch, and not async or future? Both of those coroutine builders assume that somebody will synchronize on its result, and thus receive the propagated exception? This is then a very important reason not to use something like async { ... }.join()?