코루틴 종료 멈추기

suspend fun main(): Unit = coroutineScope {
    try {
        launch {
            throw NullPointerException()
            repeat(10) {
                println(it)
            }
        }
        delay(1000)
        println("끝")
        delay(1000)
    } catch(e: Exception) {
        println("test")
    }
}

NullPointerException가 발생하게됨.

suspend fun main(): Unit = coroutineScope {
    try {
        launch {
            try {
                throw NullPointerException()
                repeat(10) {
                    println(it)
                }
            } catch (e: Exception) {
                println("test1")
            }

        }
        delay(1000)
        println("끝")
        delay(1000)
    } catch(e: Exception) {
        println("test")
    }
}

SupervisorJob

fun main(): Unit = runBlocking {
     launch(SupervisorJob()) { 
         launch {
             delay(1000)
             throw Error("Some error")
         }
             
         launch { 
             delay(2000)
             println("Will not be printed")
         }
     }
     delay(3000)
}

supervisorScope