Kotlin 协程异常,聚合异常 多个异常的处理
Posted 安果移不动
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kotlin 协程异常,聚合异常 多个异常的处理相关的知识,希望对你有一定的参考价值。
@Test
fun `test exception aggregation`() = runBlocking<Unit>
val coroutineExceptionHandler = CoroutineExceptionHandler _, exception ->
println("Caught $exception $exception.suppressed.contentToString()")
val job = GlobalScope.launch(coroutineExceptionHandler)
launch
try
delay(Long.MAX_VALUE)
finally
throw ArithmeticException()
launch
try
delay(Long.MAX_VALUE)
finally
throw IndexOutOfBoundsException()
launch
delay(100)
throw IOException()
job.join()
以上是关于Kotlin 协程异常,聚合异常 多个异常的处理的主要内容,如果未能解决你的问题,请参考以下文章