Nguyễn Nhật Tân
03/10/2025, 7:44 AMfun main(): Unit = runBlocking {
    val scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO> + SupervisorJob())
    scope.launch {
        delay(1000)
        throw Error("Child 1 failed")
    }
    scope.launch {
        delay(1500)
        println("Child 2 Success")
    }
    // Wait
    delay(3000)
}Exception in thread "DefaultDispatcher-worker-3 @coroutine#2" java.lang.Error: Child 1 failed
 //stacktrace
Child 2 SuccessviewModelScope.launch {
    delay(1000)
    throw Error("Child 1 failed")
}
viewModelScope.launch {
    delay(1500)
    println("Child 2 Success")
}FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 6877
java.lang.Error: Child 1 failed
 at..."Child 2 Success"SupervisorJobCoroutineExceptionHandlertry-catchDmitry Khalanskiy [JB]
03/10/2025, 10:46 AMDoes this mean that, by default in Android, we do not benefit fromIt does not mean that.at all?SupervisorJob
SupervisorJobWe still need to handle exceptions usingYes, if a coroutine is `launch`'ed (instead of being created withor aCoroutineExceptionHandlerblock?try-catch
asyncCoroutineExceptionHandlerKotlin Coroutine documentation provides examples that are suitable for regular Java/Kotlin programsCould you please provide links to these examples?
louiscad
04/10/2025, 10:49 PMval scope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO> + SupervisorJob())supervisorScope { … }Dmitry Khalanskiy [JB]
04/11/2025, 7:01 AMCould lead to coroutines being garbage collected while suspended.I think you're talking about https://github.com/Kotlin/kotlinx.coroutines/issues/1061, but for this to be a problem, you need someone who would want to potentially wake up a coroutine to store it as a weak reference.
louiscad
04/12/2025, 9:17 AMMediaPlayerContinuationImplMediaPlayerMediaPlayerJobCoroutineScopelouiscad
04/12/2025, 9:17 AMGlobalScopeDmitry Khalanskiy [JB]
04/14/2025, 7:24 AMAny API can do this kind of thing, directly, or indirectly.That also means you can't directly pass lambdas/anonymous classes to this API at all, as those are not strongly referenced, which makes the API error-prone. Every user of
MediaPlayerlouiscad
04/14/2025, 12:54 PMDmitry Khalanskiy [JB]
04/14/2025, 1:05 PMMediaPlayerMediaPlayerlouiscad
04/14/2025, 2:53 PMDmitry Khalanskiy [JB]
04/14/2025, 3:00 PMSharedFlowSharedFlowlouiscad
04/14/2025, 3:02 PMlouiscad
04/14/2025, 3:02 PMDmitry Khalanskiy [JB]
04/14/2025, 3:05 PMCoroutineScope()