From 603705aa1c80c2b0c2ffdc381b91438948c514b7 Mon Sep 17 00:00:00 2001 From: tetraquark Date: Thu, 17 Jun 2021 02:18:59 +0700 Subject: [PATCH] #19 catching Exception instead Throwable and rethrowing CancellationException in ExceptionHandlerContextImpl --- .../moko/errors/handler/ExceptionHandlerContextImpl.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerContextImpl.kt b/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerContextImpl.kt index 6284d1c..3eebe36 100644 --- a/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerContextImpl.kt +++ b/errors/src/commonMain/kotlin/dev/icerock/moko/errors/handler/ExceptionHandlerContextImpl.kt @@ -7,6 +7,7 @@ package dev.icerock.moko.errors.handler import dev.icerock.moko.errors.ErrorEventListener import dev.icerock.moko.errors.HandlerResult import dev.icerock.moko.mvvm.dispatcher.EventsDispatcher +import kotlinx.coroutines.CancellationException import kotlin.reflect.KClass private typealias Catcher = (Throwable) -> Boolean @@ -38,7 +39,9 @@ internal class ExceptionHandlerContextImpl( override suspend fun execute(): HandlerResult { return try { HandlerResult.Success(block()) - } catch (e: Throwable) { + } catch (e: Exception) { + // Don't handle coroutines CancellationException + if (e is CancellationException) throw e onCatch?.invoke(e) val isHandled = catchersMap[e::class]?.invoke(e) if (isHandled == null || isHandled == false) {