Last active
February 28, 2022 13:39
-
-
Save chenzhang2006/319df989f03487e1b3bc96d14c038032 to your computer and use it in GitHub Desktop.
Define CoroutineExceptionHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseViewModel<S : BaseState> : ViewModel(), MviViewModel<S> { | |
private val exceptionHandler = CoroutineExceptionHandler { context, throwable -> | |
// 1. Trigger event to prompt error dialog | |
// 2. Log to tracking system for observability | |
} | |
private val job = SupervisorJob() | |
private val context = Dispatchers.Main + job + exceptionHandler | |
protected val coroutineScope = CoroutineScope(context) | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment