diff --git a/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt b/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt index 9675e9536..e51913285 100644 --- a/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt +++ b/server/core/src/main/java/dev/slimevr/util/SafeLaunch.kt @@ -25,10 +25,14 @@ fun CoroutineScope.safeLaunch( start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit, ): Job { - val handler = context[CoroutineExceptionHandler] ?: CoroutineExceptionHandler { ctx, throwable -> - val name = ctx[CoroutineName]?.name ?: "UnknownScope" - AppLogger.coroutines.error(throwable, "Unhandled exception in safeLaunch (scope: $name)") - } + val handler = context[CoroutineExceptionHandler] + ?: this.coroutineContext[CoroutineExceptionHandler] + ?: CoroutineExceptionHandler { ctx, throwable -> + val name = ctx[CoroutineName]?.name ?: "UnknownScope" + AppLogger.coroutines.error( + throwable, "Unhandled exception in safeLaunch (scope: $name)" + ) + } //noinspection RAW_LAUNCH_USAGE return this.launch(context + handler, start = start, block = block) }