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

catch in ExceptionHandler require class equality #13

Closed Alex009 closed 3 years ago

Alex009 commented 3 years ago

If we use this code:

exceptionHandler.handle { 
    request()
}.catch<Exception> { 
    false
}.execute()

catch blog will not be execute if throw some of subclasses of Exception. it's imprudent behavior, because try-catch allow to catch all subclasses of some type. We should improve it to same logic.


to implement this i think we should remove KClass map and use lambda with conditions.

inline fun <reified E : Throwable> catch(noinline catcher: (E) -> Boolean)

become

inline fun <reified E : Throwable> catch(
    noinline catcher: (E) -> Boolean
): ExceptionHandlerContext<R> {
    return catch(condition = { it is E }, catcher = catcher)
}