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

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.
主站蜘蛛池模板: 山阳县| 林西县| 招远市| 新巴尔虎左旗| 五家渠市| 泸西县| 奇台县| 岗巴县| 微山县| 右玉县| 青铜峡市| 云阳县| 郑州市| 彰化县| 湄潭县| 义乌市| 疏勒县| 石城县| 观塘区| 南澳县| 佛教| 龙门县| 德清县| 阆中市| 吴桥县| 潞城市| 项城市| 南江县| 泽州县| 鄂托克前旗| 简阳市| 丘北县| 奇台县| 米林县| 红桥区| 邵阳市| 大新县| 东安县| 宜川县| 深州市| 大邑县|