You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
suspend fun getSum(): Int {
var sum = 0
repeat(3) {
delay(500)
sum += it
if (it == 2)
throw RuntimeException("Exception")
}
return sum
}
fun main() = runBlocking {
val res = async {
getSum()
}
val sum = runCatching { res.await() }
if(sum.isSuccess) println("sum is: ${sum.getOrNull()}") else println("error sum: ${sum.exceptionOrNull()?.message}")
println("end")
}
i expected with runCatching {..} i avoid exception trace but i already see exception trace still printed and my execution finish with code 1 (expected 0)
whats wrong and how to handle exception with coroutines (without using GlobaleScope)
The text was updated successfully, but these errors were encountered:
hi
this is a snapshot of my test:
i expected with runCatching {..} i avoid exception trace but i already see exception trace still printed and my execution finish with code 1 (expected 0)
whats wrong and how to handle exception with coroutines (without using GlobaleScope)
The text was updated successfully, but these errors were encountered: