Health Connect throws standard exceptions for CRUD operations when an issue is encountered. Your app should catch and handle each of these exceptions as appropriate.
Each method on HealthConnectClient
lists the exceptions that can be thrown.
In general, your app should handle the following exceptions:
Exception | Description | Recommended best practice |
---|---|---|
SecurityException
| There are issues encountered when the requests require permissions that aren't granted. | To avoid this, make sure that you've declared use of Health Connect data types for your published app. Also, you must declare Health Connect permissions in the manifest file and in your activity. |
IOException
| There are issues encountered upon reading and writing data from disk. | To avoid this issue, here are some suggestions:
|
IllegalStateException
| One of the following scenarios has occurred:
| Handle possible issues with the inputs first before doing a request. Preferably, assign values to variables or use them as parameters within a custom function instead of using them directly in your requests so that you can apply error handling strategies. |
RemoteException
| Errors have occurred within, or in communicating
with, the underlying service to which the SDK connects. For example, your app is trying to delete a record with a given uid . However, the exception
is thrown after the app finds out upon checking in the underlying service that
the record doesn't exist.
| To avoid this issue, here are some suggestions:
|