Coverage Summary for Class: ExceptionHandler (cloud.mindbox.mobile_sdk.utils)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| ExceptionHandler |
100%
(7/7)
|
100%
(4/4)
|
100%
(11/11)
|
100%
(116/116)
|
| ExceptionHandler$runCatching$1 |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(2/2)
|
| ExceptionHandler$runCatchingSuspending$3 |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(2/2)
|
| ExceptionHandler$runCatchingSuspending$4 |
|
| Total |
100%
(9/9)
|
100%
(4/4)
|
100%
(13/13)
|
100%
(120/120)
|
package cloud.mindbox.mobile_sdk.utils
/**
* A class for internal sdk work only. Do not extend or use it
* */
public abstract class ExceptionHandler {
public fun <T> runCatching(block: () -> T) {
runCatching(Unit, block)
}
public suspend fun <T> runCatchingSuspending(block: suspend () -> T) {
runCatchingSuspending(Unit, block)
}
public fun <T> runCatching(
defaultValue: T,
block: () -> T,
): T = runCatching(block = block) { defaultValue }
public suspend fun <T> runCatchingSuspending(
defaultValue: T,
block: suspend () -> T,
): T = runCatchingSuspending(block = block) { defaultValue }
public fun <T> runCatching(
block: () -> T,
defaultValue: (Throwable) -> T,
): T = kotlin.runCatching { block.invoke() }.getOrElse { exception ->
handle(exception)
defaultValue.invoke(exception)
}
public suspend fun <T> runCatchingSuspending(
block: suspend () -> T,
defaultValue: (Throwable) -> T,
): T = kotlin.runCatching { block.invoke() }.getOrElse { exception ->
handle(exception)
defaultValue.invoke(exception)
}
protected abstract fun handle(exception: Throwable)
}