``` fun main(args: Array<String>) = runBlock...
# coroutines
m
Copy code
fun main(args: Array<String>) = runBlocking<Unit> {
    try {
        failedConcurrentSum()
    } catch(e: ArithmeticException) {
        println("Computation failed with ArithmeticException")
    }
}

suspend fun failedConcurrentSum(): Int = coroutineScope {
    val one = async<Int> { 
        try {
            delay(Long.MAX_VALUE) // Emulates very long computation
            42
        } finally {
            println("First child was cancelled")
        }
    }
    val two = async<Int> { 
        println("Second child throws an exception")
        throw ArithmeticException()
    }
        one.await() + two.await()
}
it doesnt seem to work for me. The parent coroutine still blocks waiting for the first
async
after the second threw the exception
v
Have you updated your coroutines version to 0.30.1?
d
The reason is that the
two
coroutine doesn't throw its exception until you call
two.await()
which doesn't occur until
one.await()
returns.
If the exception thrown by
two
is supposed to cancel the parent before
await()
is called then I guess I don't know.
v
@Dico this behaviour was changed in the latest realese
1