Ivan Harnastaeu
05/02/2024, 8:32 AMThrows(Exception::class)
.
Here's how it looks:
@Throws(Exception::class)
fun deviceFlow(): Flow<BLEDevice> {
return scanner.advertisements
.filter { !it.name.isNullOrBlank() }
.map {
BLEDevice(
name = it.name.orEmpty(),
advertisement = it
)
}
}
}
If I just throw an Exception in the body of this function, it works fine. But if I run it on a device without Bluetooth usage permission, the function awaitPoweredOn()
throws an exception and crashes the app and does not propagate this exception further. And I would like to handle such exceptions on the client side.
Thanks in advance!travis
05/02/2024, 8:38 AMFlow
rather than the function. If that is the case, I would advise you to look into https://github.com/rickclephas/KMP-NativeCoroutines. It allows you more easily collect data from `Flow`s (from Swift) and handle failures that may be emitted as well.travis
05/02/2024, 8:42 AMdeviceFlow
function return a Flow
, you could have it return a single item (the item of interest). Essentially, you could use a terminal flow operator (e.g. first
), as a terminal flow operator will propagate any flow exceptions.Ivan Harnastaeu
05/02/2024, 10:10 AM