Ble Exception
Base exception class for all BLE-related errors in the BleX library.
This sealed class hierarchy provides a type-safe way to handle different categories of BLE errors. Each subclass represents a specific type of failure that can occur during BLE operations.
Exception Hierarchy
BleConnectionException - Connection establishment or maintenance failures
BleCharacteristicException - Characteristic read/write/notify operation failures
BleTimeoutException - Operation timeout errors
BleNotFoundException - Service or characteristic not found errors
BlePermissionException - Missing Android permissions errors
Usage Example
try {
connection.readCharacteristicResult(serviceUuid, charUuid)
.onSuccess { data -> processData(data) }
.onFailure { error ->
when (error) {
is BleConnectionException -> handleConnectionError(error)
is BleCharacteristicException -> handleCharacteristicError(error)
is BleTimeoutException -> retryOperation()
is BleNotFoundException -> logMissingService(error)
is BlePermissionException -> requestPermissions(error.missingPermissions)
}
}
} catch (e: BleException) {
Log.e("BLE", "GATT status: ${e.gattStatus}, message: ${e.message}")
}Content copied to clipboard