官术网_书友最值得收藏!

Exception handling

By default, an exception happening inside a job will be propagated to where it was created. This happens even if we aren't waiting for the job to complete. Consider this example:

fun main(args: Array<String>) = runBlocking {
launch {
TODO("Not Implemented!")
}

delay(500)
}
Here, we use delay() to have the app run for enough time so that the exception is thrown. We aren't using join() on purpose, to show that the exception will be propagated regardless of us waiting for the job to complete.

This will propagate the exception to the uncaught exception handler of the current thread. In a JVM application, this means that the exception will be printed on standard error output, as illustrated:

As we move ahead, we will see how to use CoroutineExceptionHandler and invokeOnCompletion() to handle exceptions.
主站蜘蛛池模板: 嵊州市| 靖西县| 大田县| 手游| 灌阳县| 凤阳县| 玉门市| 惠东县| 灵寿县| 石城县| 靖远县| 安平县| 临武县| 东城区| 沁源县| 绥化市| 湘潭县| 加查县| 横山县| 观塘区| 宜川县| 凤凰县| 钟山县| 昌乐县| 美姑县| 红河县| 留坝县| 瑞金市| 阿拉善盟| 长丰县| 安溪县| 新民市| 刚察县| 明光市| 大港区| 巍山| 开化县| 博湖县| 琼海市| 天镇县| 平江县|