icerockdev / moko-errors

Automated exceptions handler for mobile (android & ios) Kotlin Multiplatform development.
https://moko.icerock.dev/
Apache License 2.0
52 stars 6 forks source link

Remove requirement of call execute #6

Open Alex009 opened 4 years ago

Alex009 commented 4 years ago
// now
    viewModelScope.launch {
        exceptionHandler.handle {
            serverRequest()
        }.catch<IllegalArgumentException> {     // Specifying a specific exception class
            // Some custom handler code
            false                               // true - cancels ErrorPresenter; false - allows execution of ErrorsPresenter
        }.execute()                             // Starts code execution in `handle` lambda
    }
    // suggestion
    viewModelScope.launch {
        isLoading = true
        val result = exceptionHandler {
            action {
                serverRequest()
            }
            catch<IllegalAccessException> { exc ->
                // Some custom handler code
                false                               // true - cancels ErrorPresenter; false - allows execution of ErrorsPresenter
            }
            catch<IllegalArgumentException> { exc ->
                // Some custom handler code
                false                               // true - cancels ErrorPresenter; false - allows execution of ErrorsPresenter
            }
            finally {
                isLoading = false
            }
        }
    }
Alex009 commented 4 years ago

https://kotlinlang.org/docs/reference/type-safe-builders.html#scope-control-dslmarker-since-11