Skip to content

Instantly share code, notes, and snippets.

@sembozdemir
Created April 25, 2018 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sembozdemir/9fed1cee5276fe227db2366e9156a99e to your computer and use it in GitHub Desktop.
Save sembozdemir/9fed1cee5276fe227db2366e9156a99e to your computer and use it in GitHub Desktop.
logException
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