Skip to content

Instantly share code, notes, and snippets.

@chenzhang2006
Last active February 28, 2022 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenzhang2006/319df989f03487e1b3bc96d14c038032 to your computer and use it in GitHub Desktop.
Save chenzhang2006/319df989f03487e1b3bc96d14c038032 to your computer and use it in GitHub Desktop.
Define CoroutineExceptionHandler
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