Last active
April 1, 2022 17:33
-
-
Save chenzhang2006/6b04095ca5fd76ce4470ca01d93dc8af to your computer and use it in GitHub Desktop.
Full helper to handle exceptions
This file contains 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
internal suspend inline fun <T> getResult(block: () -> T): Result<T> = try { | |
block().let { Result.success(it) } | |
} catch (e: Exception) { | |
if (e is CancellationException) throw e | |
Timber.e("Error from coroutine (${coroutineContext[CoroutineName]?.name}): " + | |
"${e.stackTraceToString()}") | |
Result.failure(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment