Last active
February 11, 2019 18:52
-
-
Save raxityo/8a109787966abc38c27b5620ce93b225 to your computer and use it in GitHub Desktop.
A Kotlin extension to introduce optional chaining to error handling.
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
inline fun <T> tryOptional(expression: () -> T): T? { | |
return try { | |
expression() | |
} catch (ex: Throwable) { | |
null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: