איתור חריגים וטיפול בהם
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
Health Connect מקפיצה חריגות רגילות לפעולות CRUD כאשר יש בעיה
המערכת נתקלה בבעיה. האפליקציה שלך צריכה לזהות כל אחד מהחריגים האלה ולטפל בהם בתור
המתאים.
כל שיטה ב-HealthConnectClient
מציגה את רשימת החריגים שאפשר להשליך.
באופן כללי, האפליקציה צריכה לטפל בחריגים הבאים:
חריג |
תיאור |
שיטה מומלצת |
SecurityException
| יש בעיות שהבקשות מצריכות
הרשאות שלא הוענקו.
| כדי להימנע מכך, חשוב להקפיד
שימוש מוצהר בסוגי הנתונים של Health Connect בתוכן שפורסם
אפליקציה. בנוסף, צריך להצהיר על הרשאות של Health Connect
בקובץ המניפסט ובפעילות שלכם.
|
IOException
| יש בעיות במהלך קריאה וכתיבה של נתונים מתוך
לדיסק און קי.
| כדי למנוע מראש את הבעיה, הנה כמה הצעות:
- גיבוי כל הקלט של המשתמשים.
- להיות מסוגלים לטפל בבעיות שמתרחשות במהלך פעולות של כתיבה בכמות גדולה. עבור
לדוגמה, ודאו שהתהליך עובר מעבר לבעיה ומבצעים את
הפעולות שנותרו.
- להחיל אסטרטגיות של ניסיונות חוזרים והשהיה לפני ניסיון חוזר (backoff) כדי לטפל בבעיות של בקשות.
|
IllegalStateException
| אחד מהתרחישים הבאים מתרחש:
- שירות Health Connect לא זמין.
- הבקשה היא לא מבנה חוקי. לדוגמה, בקשה מצטברת ב-
קטגוריות תקופתיות שבהן נעשה שימוש באובייקט
Instant בשביל timeRangeFilter .
| לפני ששולחים בקשה, צריך קודם לטפל בבעיות אפשריות בקלט.
עדיף להקצות ערכים למשתנים או להשתמש בהם כפרמטרים בתוך
במקום להשתמש בהם ישירות בבקשות, כך שאפשר להחיל
אסטרטגיות לטיפול בשגיאות.
|
RemoteException
| אירעו שגיאות במהלך התקשורת או במהלך התקשורת
בשירות הבסיסי שאליו ה-SDK מתחבר.
למשל,
האפליקציה שלך מנסה למחוק רשומה עם uid נתון. עם זאת, יוצא הדופן
מועברת אחרי שהאפליקציה מגלה בבדיקה בשירות הבסיסי
הרשומה לא קיימת.
| כדי למנוע מראש את הבעיה, הנה כמה הצעות:
- רצוי לסנכרן באופן קבוע בין מאגר הנתונים של האפליקציה לבין Health Connect.
- להחיל אסטרטגיות של ניסיונות חוזרים והשהיה לפני ניסיון חוזר (backoff) כדי לטפל בבעיות של בקשות.
|
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 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"]]