``` launch { try { async { throw IOExc...
# coroutines
w
Copy code
launch {
    try {
        async { throw IOException() }.await()
    } catch (e: IOException) {
    }
}
I get an uncaught IOException. What is wrong?
Copy code
async {
    try {
        async { throw IOException() }.await()
    } catch (e: IOException) {
    }
}
I get no Exception.
j
This is because
async
is a child of
launch
making it fail imediately.
If the parent is an
async
it is the same, but exception is not logged, because you're supposed to call
await
Just favor suspending function and you'll be fine
One need
async
only for parallel decomposition. For other uses-cases just use suspending functions (without using
async
at all)
w
Oh, nice URL. Thanks!