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

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.
主站蜘蛛池模板: 沁阳市| 邵武市| 南宁市| 渝中区| 枞阳县| 英德市| 突泉县| 赣榆县| 南阳市| 永川市| 同心县| 漠河县| 鸡西市| 镶黄旗| 黔东| 六枝特区| 汉川市| 濮阳县| 昌黎县| 昌黎县| 沙田区| 玉树县| 吴忠市| 冷水江市| 沙坪坝区| 高密市| 磐石市| 栾川县| 上思县| 全椒县| 贺兰县| 沙洋县| 故城县| 华蓥市| 十堰市| 临猗县| 普格县| 马尔康县| 清新县| 蒲城县| 泰州市|