Sobes.tech
Back to tasks
Junior — Senior
43

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

Get help with live coding in real time with Sobes Copilot
Task condition

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

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