Djuro
12/21/2023, 9:43 PMmoko-mvvm
library and am using their dev.icerock.moko.mvvm.viewmodel.ViewModel
Of course, inside of it there is its own viewmodelScope
I am encountering an error where viewmodelScope
is getting cancelled and the CoroutineExceptionHandler
is not working properly
Here is a small sample
class MyViewModel: ViewModel() {
init {
viewModelScope.coroutineContext[Job]?.invokeOnCompletion {
Logger.e { "Viewmodel scope finished lol what the heck " }
}
}
fun foo(){
viewModelScope.launch(
CoroutineExceptionHandler { _, throwable: Throwable ->
Logger.e(throwable) { "foo failed" }
}
) {
throw Exception("ohoh")
}
}
When user calls foo
and it of course fails due to the thrown exception, invokeOnCompletion
shouldn't be called, but it is called.
Am I doing something wrong but as far as I know coroutines, after installing a coroutine exception handler on a coroutine it shouldn't cancel the scope 🤷, is this a viewmodelScope a SupervisorJob
or not, I don't think that even the normal scope should be cancelled in this case?Djuro
12/21/2023, 9:51 PMDjuro
12/21/2023, 10:04 PMDjuro
12/25/2023, 8:00 PM