Catch and handle exceptions
Stay organized with collections
Save and categorize content based on your preferences.
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:
- Back up any user input.
- Be able to handle any issues that occur during bulk write operations. For
example, make sure the process moves past the issue and carry out the
remaining operations.
- Apply retries and backoff strategies to handle request issues.
|
IllegalStateException
| One of the following scenarios has occurred:
- The Health Connect service isn't available.
- The request isn't a valid construction. For example, an aggregate request in
periodic buckets where an
Instant object is used for the timeRangeFilter .
| 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:
- Perform regular syncs between your app's datastore and Health Connect.
- Apply retries and backoff strategies to handle request issues.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-09-04 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-09-04 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-04 UTC."]]