Coverage Summary for Class: ExceptionHandler (cloud.mindbox.mobile_sdk.utils)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| ExceptionHandler |
100%
(7/7)
|
75%
(3/4)
|
81.8%
(9/11)
|
94%
(109/116)
|
| ExceptionHandler$runCatching$1 |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(2/2)
|
| ExceptionHandler$runCatchingSuspending$3 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/2)
|
| ExceptionHandler$runCatchingSuspending$4 |
|
| Total |
88.9%
(8/9)
|
75%
(3/4)
|
76.9%
(10/13)
|
92.5%
(111/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)
}