Filip Wiesner
04/22/2021, 6:54 PMSupervisorJob (viewModelScope) throws exception?
My use case is that when debugging I want my app to crash whenever there is unhandled exception anywhere in my business logic but because viewModelScope is SupervisorJob, the coroutine is only getting cancelled.
This behavior can be achieved by using Dispatchers.Main as context (presumably because it calls android UncaughtExceptionHandler) but I how can I achieve this when using .Default or .IO dispatchers?Filip Wiesner
04/22/2021, 6:56 PMCoroutineExceptionHandler and re-throwing the exception but without luck.Zach Klippenstein (he/him) [MOD]
04/22/2021, 7:11 PMFilip Wiesner
04/22/2021, 7:14 PMZach Klippenstein (he/him) [MOD]
04/22/2021, 7:20 PMlouiscad
04/22/2021, 8:22 PMlaunch (but not async which should be part of a child non supervisor scope.uli
04/23/2021, 6:49 AMFilip Wiesner
04/23/2021, 7:39 AMcoroutineScope and it only crashes when I'm using Dispatchers.Main.
Any tips on where should I look to resolve this?
My coroutine structure:
viewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>)
withContext(Dispatchers.Default)
coroutineScope
async
await - exception is thrown
OR
viewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>)
withContext(Dispatchers.Default)
exception is thrown
Neither of those crash the appFilip Wiesner
04/23/2021, 7:40 AMviewModelScope.launch(Dispatchers.Main). The rest is the samelouiscad
04/23/2021, 7:44 AMFilip Wiesner
04/23/2021, 7:52 AM.Main dispatcher?louiscad
04/23/2021, 8:04 AMlifecycleScope in an Activity or only in viewmModelScope? Which AndroidX ViewModel KTX version are you using?Filip Wiesner
04/23/2021, 8:06 AMlifecycleScope. Gimme a secFilip Wiesner
04/23/2021, 8:13 AMAlex Vasilkov
04/23/2021, 8:53 AMviewModelScope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
withContext(Dispatchers.Default) {
throw RuntimeException("TEST")
}
}
Are you sure that the thrown exception is not CancellationException or its subclass? 🙂Filip Wiesner
04/23/2021, 9:32 AMlouiscad
04/23/2021, 9:33 AMThread.setUncaughtExceptionHandler in your project.Filip Wiesner
04/23/2021, 10:30 AMGlobalScope.launch {
error("")
}
inside a ViewModel and it still does not crash...Filip Wiesner
04/23/2021, 10:32 AMFilip Wiesner
04/23/2021, 2:49 PMlouiscad
04/23/2021, 2:55 PMFilip Wiesner
04/23/2021, 3:08 PMFilip Wiesner
04/23/2021, 3:24 PMlouiscad
04/23/2021, 4:26 PMFilip Wiesner
04/23/2021, 6:04 PMlouiscad
04/23/2021, 8:28 PM