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

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.
主站蜘蛛池模板: 视频| 清涧县| 延吉市| 汤原县| 沙洋县| 曲沃县| 贵定县| 泗水县| 宁蒗| 常宁市| 方山县| 丹东市| 锦屏县| 晋州市| 延吉市| 金寨县| 攀枝花市| 乌什县| 合肥市| 许昌市| 谷城县| 丘北县| 兴义市| 思茅市| 阳东县| 清流县| 阿巴嘎旗| 洪泽县| 汪清县| 广西| 徐水县| 镇雄县| 白沙| 三台县| 静安区| 承德市| 观塘区| 华阴市| 钦州市| 黄浦区| 修文县|