Created
June 12, 2022 15:14
-
-
Save rubenquadros/f614269096a2629f036a5055fc48bba7 to your computer and use it in GitHub Desktop.
Default exception handler for all unhandled exceptions
This file contains hidden or 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
////////////////////////////////////////////// | |
// 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