Rilevamento e gestione delle eccezioni
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Connessione Salute genera eccezioni standard per le operazioni CRUD quando un problema viene rilevato
riscontrati. L'app deve rilevare e gestire ciascuna di queste eccezioni come
appropriato.
Ogni metodo su HealthConnectClient
elenca le eccezioni che è possibile generare.
In generale, l'app deve gestire le seguenti eccezioni:
Eccezione |
Descrizione |
Best practice consigliata |
SecurityException
| Si sono verificati problemi quando le richieste richiedono
autorizzazioni non concesse.
| Per evitare che ciò accada, assicurati di avere
dichiarato di utilizzo dei tipi di dati di Connessione Salute per i tuoi contenuti pubblicati
dell'app. Inoltre, devi dichiarare le autorizzazioni di Connessione Salute
nel file manifest e nella tua attività.
|
IOException
| Si sono verificati problemi durante la lettura e la scrittura dei dati da
disco.
| Per evitare il problema, ecco alcuni suggerimenti:
- Esegui il backup di qualsiasi input utente.
- Essere in grado di gestire eventuali problemi che si verificano durante le operazioni di scrittura collettiva. Per
Ad esempio, assicurati che la procedura superi il problema ed esegui la
le operazioni rimanenti.
- Applicare nuovi tentativi e strategie di backoff per gestire i problemi delle richieste.
|
IllegalStateException
| Si è verificato uno dei seguenti scenari:
- Il servizio Connessione Salute non è disponibile.
- La richiesta non è una costruzione valida. Ad esempio, una richiesta aggregata
bucket periodici in cui viene utilizzato un oggetto
Instant per timeRangeFilter .
| Gestisci i possibili problemi con gli input prima di eseguire una richiesta.
Preferibilmente, assegna valori alle variabili o utilizzali come parametri all'interno di un
invece di usarle direttamente nelle tue richieste, in modo che tu possa
strategie di gestione degli errori.
|
RemoteException
| Si sono verificati errori all'interno di o durante la comunicazione
con il servizio sottostante a cui si connette l'SDK.
Ad esempio,
la tua app sta tentando di eliminare un record con un determinato uid . Tuttavia, l'eccezione
viene generata dopo che l'app scopre, al momento del controllo nel servizio sottostante,
il record non esiste.
| Per evitare il problema, ecco alcuni suggerimenti:
- Esegui sincronizzazioni regolari tra il datastore della tua app e Connessione Salute.
- Applicare nuovi tentativi e strategie di backoff per gestire i problemi delle richieste.
|
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-27 UTC."],[],[],null,["# Catch and handle exceptions\n\nHealth Connect throws standard exceptions for CRUD operations when an issue is\nencountered. Your app should catch and handle each of these exceptions as\nappropriate.\n\nEach method on `HealthConnectClient` lists the exceptions that can be thrown.\nIn general, your app should handle the following exceptions:\n\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| **Exception** | **Description** | **Recommended best practice** |\n|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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](/guide/health-and-fitness/health-connect/develop/frequently-asked-questions#declare-access) for your published app. Also, you must declare Health Connect permissions [in the manifest file](/guide/health-and-fitness/health-connect/develop/get-started#step-3) and [in your activity](/guide/health-and-fitness/health-connect/develop/get-started#step-4). \u003cbr /\u003e \u003cbr /\u003e |\n| `IOException` | There are issues encountered upon reading and writing data from disk. | To avoid this issue, here are some suggestions: \u003cbr /\u003e - 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. \u003cbr /\u003e |\n| `IllegalStateException` | One of the following scenarios has occurred: \u003cbr /\u003e - 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`. \u003cbr /\u003e | 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. |\n| `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: \u003cbr /\u003e - Perform regular syncs between your app's datastore and Health Connect. - Apply retries and backoff strategies to handle request issues. \u003cbr /\u003e |\n\n\u003cbr /\u003e"]]