阅读背景:

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()
    }    @Test
    fun `test exception aggregatio



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: