Skip to content

Commit

Permalink
fix catching issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusMcCloud committed Jun 10, 2024
1 parent 1938dc1 commit 46df062
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/commonMain/kotlin/at/asitplus/KmmResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ private constructor(
* Re-throws any fatal exceptions, such as `OutOfMemoryError`. Relies on [Arrow](https://arrow-kt.io)'s
* [nonFatalOrThrow](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) internally.
*/
inline fun <reified T> catching(block: () -> T): KmmResult<T> {
@Suppress("TooGenericExceptionCaught")
inline fun <T> catching(block: () -> T): KmmResult<T> {
return try {
KmmResult.success(block())
} catch (e: Throwable) {
Expand All @@ -220,10 +221,11 @@ inline fun <reified T> catching(block: () -> T): KmmResult<T> {
* Re-throws any fatal exceptions, such as `OutOfMemoryError`. Relies on [Arrow](https://arrow-kt.io)'s
* [nonFatalOrThrow](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) internally.
*/
inline fun <T, reified R> T.catching(block: T.() -> R): KmmResult<R> {
@Suppress("TooGenericExceptionCaught")
inline fun <T, R> T.catching(block: T.() -> R): KmmResult<R> {
return try {
KmmResult.success(block())
} catch (e: Throwable) {
KmmResult.failure(e)
}
}
}

0 comments on commit 46df062

Please sign in to comment.