Sobes.tech
Junior — Senior
96

Разбор поведения кода с CoroutineExceptionHandler

任务条件

Определить, какое действие произойдёт при запуске следующего фрагмента кода.

fun main() {

    val coroutineExceptionHandler = CoroutineExceptionHandler { coroutineContext, exception ->
        println("Handle $exception in CoroutineExceptionHandler")
    }

    val topLevelScope = CoroutineScope(Job())

    topLevelScope.launch {
        launch(coroutineExceptionHandler) {
            throw RuntimeException("RuntimeException in nested coroutine")
        }
    }
}