Skip to content

Instantly share code, notes, and snippets.

@charbgr
Last active October 27, 2016 15:10
Show Gist options
  • Save charbgr/424226de50c63471154ae54ab297aa88 to your computer and use it in GitHub Desktop.
Save charbgr/424226de50c63471154ae54ab297aa88 to your computer and use it in GitHub Desktop.
ErrorHandler Kotlin Extension
/**
* 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