0

I am trying to make DmsExceptionHandler catch global application exception. But when the DmsExceptionHandler catches the exception, the application stops without crashing. However, UI components; like bottom navigation can be clicked, and ripple effect is shown. But never changes the screen.

internal class DmsExceptionHandler @Inject constructor(
    private val context: Context,
    private val appState: DmsAppState,
) : Thread.UncaughtExceptionHandler {

    override fun uncaughtException(
        thread: Thread,
        exception: Throwable,
    ) {
        when (exception) {
            is CommonException.SignInRequired -> signInRequired()
            else -> {
                signInRequired() // todo replace
            }
        }
    }

    private fun signInRequired() {
        appState.navigateToSignIn()
    }
}

If i make uncaughtException do not call signInRequired(), the application does not stop.

internal fun DmsAppState.navigateToSignIn() {
    println("NAVIGATED TO SIGN IN")
    this.navController.navigate(DmsRoute.Auth.route) {/*
        popUpTo(this@navigateToSignIn.navController.graph.startDestinationId) {
            saveState = true
        }*/
    }
}
JunJaBoy
  • 25
  • 4
  • You cannot recover from every RuntimeException. Have you tried...just fixing your exceptions? – ianhanniballake May 31 '23 at 02:14
  • when device's token has expired, application will throw TokenExpiredException(from data layer). then the handler(from app layer) will catch this exception, and the screen will be navigated to sign in screen – JunJaBoy May 31 '23 at 02:42

0 Answers0