aaverin
08/24/2018, 5:41 AMawait()
call in try/catch I might never ever know that there was an exception inside? Or will that exception then thrown as usual?
fun main(args: Array<String>) = runBlocking {
val job = launch {
println("Throwing exception from launch")
throw IndexOutOfBoundsException() // Will be printed to the console by Thread.defaultUncaughtExceptionHandler
}
job.join()
println("Joined failed job")
val deferred = async {
println("Throwing exception from async")
throw ArithmeticException() // Nothing is printed, relying on user to call await
}
try {
deferred.await()
println("Unreached")
} catch (e: ArithmeticException) {
println("Caught ArithmeticException")
}
}
gildor
08/24/2018, 5:53 AMawait()
See this SO answer from Roman:
https://stackoverflow.com/a/46226519/420412launch
and async