Must be something trivial. Why it's not getting ca...
# coroutines
g
Must be something trivial. Why it's not getting caught?
Copy code
@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() }
		}
	}
b
have you tried just
throw Exception("Failure")
. iirc the exception handler is used for uncaught exceptions
e
It is considered a caught exception, since
runBlocking
propagates it outside. Exception handler only “catches” exceptions that would have been lost otherwise (e.g. from a globally-scoped
launch
)
g
@elizarov is it literally just
launch
, 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()
?