From cb7c0814131cea0378c62231910a7ed595e778aa Mon Sep 17 00:00:00 2001 From: hiar Date: Fri, 8 Aug 2025 15:07:20 +0200 Subject: [PATCH] Added try catch block --- .../no/nordicsemi/android/service/profile/ProfileService.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_service/src/main/java/no/nordicsemi/android/service/profile/ProfileService.kt b/lib_service/src/main/java/no/nordicsemi/android/service/profile/ProfileService.kt index fc472858..acd1d922 100644 --- a/lib_service/src/main/java/no/nordicsemi/android/service/profile/ProfileService.kt +++ b/lib_service/src/main/java/no/nordicsemi/android/service/profile/ProfileService.kt @@ -181,10 +181,10 @@ internal class ProfileService : NotificationService() { } private suspend fun connectPeripheral(peripheral: Peripheral) { - runCatching { + try { centralManager.connect(peripheral, options = ConnectionOptions.Direct()) - }.onFailure { exception -> - Timber.e(exception, "Could not connect to the ${peripheral.address}") + } catch (e: Exception) { + Timber.e(e, "Failed to connect to the ${peripheral.address}") stopForegroundService() // Stop service if connection fails } }