Sobes.tech
Назад к задачам
Junior — Senior
44

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

Получайте помощь с лайвкодингом в реальном времени с Sobes Copilot
Условие задачи

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

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")
        }
    }
}