...ok, after mulling about it for a while, I think...
# coroutines
t
...ok, after mulling about it for a while, I think I understand. The
TimeoutCancellationException
is being used as a signal for cancelling the parent Coroutine context, so the exception message (and stacktrace) are suppressed?
v
You are partially right,
TimeoutCancellationException
is used to cancel timeouted coroutine and its parent, but its not suppressed, it’s just not handled in your case.
Job
is fire and forget, but you still can handle exception (asynchronously) using
Job#invokeOnCompletion
. Or you can use
async
and call
await
on it, then exception will be propagated to call site
E.g.
Copy code
launch {
        Test().run()
        println("after run()")
    }.invokeOnCompletion { it?.apply { println(it) } }
Will print
kotlinx.coroutines.experimental.TimeoutCancellationException: Timed out waiting for 1 SECONDS
t
Ohh, @Vsevolod Tolstopyatov [JB] thanks for clarifying.