Created
April 25, 2018 15:00
-
-
Save sembozdemir/9fed1cee5276fe227db2366e9156a99e to your computer and use it in GitHub Desktop.
logException
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
inline fun <T : Exception> logException(exception: () -> T) { | |
// check if you have any precondition to report exception, | |
// for instance, is it in production? | |
if (isProductionBlaBla()) { | |
try { | |
// exception() will return a subclass of exception, so throw it | |
throw exception() | |
} catch (e: Exception) { | |
// catch exception and report it | |
CrashReportUtil.report(e) | |
} | |
} | |
} | |
// usage: | |
logException { RuntimeException("Bla bla") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment