Last active
October 27, 2016 15:10
-
-
Save charbgr/424226de50c63471154ae54ab297aa88 to your computer and use it in GitHub Desktop.
ErrorHandler Kotlin Extension
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
/** | |
* Creates a new instance of [ErrorHandler] | |
* Passing a lambda is optional | |
*/ | |
fun Throwable.handleIsolated(func: ErrorHandler.() -> Unit = {}) { | |
val errorHandler = ErrorHandler.createIsolated() | |
func(errorHandler) | |
errorHandler.handle(this) | |
} | |
/** | |
* Handles an error with the default [ErrorHandler] | |
* Passing a lambda is optional | |
*/ | |
fun Throwable.handle(func: ErrorHandler.() -> Unit = {}) { | |
val errorHandler = ErrorHandler.create() | |
func(errorHandler) | |
errorHandler.handle(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment