Skip to content

Instantly share code, notes, and snippets.

@rubenquadros
Created June 12, 2022 15:14
Show Gist options
  • Save rubenquadros/f614269096a2629f036a5055fc48bba7 to your computer and use it in GitHub Desktop.
Save rubenquadros/f614269096a2629f036a5055fc48bba7 to your computer and use it in GitHub Desktop.
Default exception handler for all unhandled exceptions
//////////////////////////////////////////////
// Activity code
//////////////////////////////////////////////
val exceptionHandler =
Thread.UncaughtExceptionHandler { _: Thread, e: Throwable ->
handleUncaughtException(e)
}
private fun attachUnhandledExceptionHandler() {
if (BuildConfig.DEBUG.not()) {
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler)
}
}
private fun handleUncaughtException(e: Throwable) {
// do something for this exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment