Skip to content

Commit 0e28421

Browse files
committed
Otus-Android#3 exception handler
1 parent 60e9018 commit 0e28421

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/src/main/java/otus/homework/coroutines/CatsViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.ViewModelProvider
55
import androidx.lifecycle.viewmodel.initializer
66
import androidx.lifecycle.viewmodel.viewModelFactory
7+
import kotlinx.coroutines.CoroutineExceptionHandler
78

89
class CatsViewModel(
910
private val catsService: CatsService,
1011
private val imageService: ImageService
1112
) : ViewModel() {
1213

14+
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
15+
CrashMonitor.trackWarning(throwable)
16+
}
17+
18+
19+
1320
companion object {
1421
fun provideFactory(
1522
catsService: CatsService,

app/src/main/java/otus/homework/coroutines/CrashMonitor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ object CrashMonitor {
55
/**
66
* Pretend this is Crashlytics/AppCenter
77
*/
8-
fun trackWarning(exception: Exception) {}
8+
fun trackWarning(exception: Throwable) {}
99
}

0 commit comments

Comments
 (0)