अपवादों को पकड़ें और हैंडल करें
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
जब कोई समस्या
मिला. आपके ऐप्लिकेशन को इनमें से हर अपवाद को
उचित.
HealthConnectClient
के हर तरीके में, दिए गए अपवादों की सूची होती है.
आम तौर पर, आपके ऐप्लिकेशन को इन अपवादों का पालन करना चाहिए:
अपवाद |
ब्यौरा |
सुझाया गया सबसे सही तरीका |
SecurityException
| अनुरोधों के लिए अनुरोध करने में समस्याएं हुईं
अनुमतियां नहीं दी गई हैं.
| इससे बचने के लिए, पक्का करें कि आपने
पब्लिश किए गए डेटा के लिए, Health Connect के अलग-अलग डेटा टाइप के इस्तेमाल का एलान
है. साथ ही, आपको Health Connect की अनुमतियों का एलान करना होगा
मेनिफ़ेस्ट फ़ाइल में और अपनी गतिविधि में.
|
IOException
| से डेटा पढ़ने और लिखने में समस्याएं हुईं
डिस्क.
| इस समस्या से बचने के लिए, यहां कुछ सुझाव दिए गए हैं:
- उपयोगकर्ता के किसी भी इनपुट का बैक अप लें.
- इन्हें बल्क में लिखने के दौरान आने वाली किसी भी समस्या को हल करने में सक्षम होना चाहिए. इसके लिए
उदाहरण के लिए, यह पक्का करें कि प्रोसेस समस्या से आगे निकल जाए और
बाकी कार्रवाइयां.
- अनुरोध से जुड़ी समस्याओं को हल करने के लिए, फिर से कोशिश करने और बैकऑफ़ की रणनीतियां लागू करें.
|
IllegalStateException
| इनमें से कोई एक स्थिति आई है:
- Health Connect सेवा उपलब्ध नहीं है.
- यह अनुरोध मान्य नहीं है. उदाहरण के लिए,
पीरियॉडिक बकेट, जहां
timeRangeFilter के लिए Instant ऑब्जेक्ट का इस्तेमाल किया जाता है.
| अनुरोध करने से पहले, इनपुट से जुड़ी संभावित समस्याओं को ठीक करें.
पसंदीदा तौर पर, वैरिएबल के लिए वैल्यू असाइन करें या उन्हें कस्टम
अपने अनुरोधों में सीधे उनका उपयोग करने के बजाय उनका उपयोग करें, ताकि आप अपने
से जुड़ी गड़बड़ियों को ठीक करने की रणनीतियां.
|
RemoteException
| बातचीत के दौरान या बातचीत करते समय गड़बड़ियां हुई हैं
जिसमें SDK टूल कनेक्ट किया गया है.
उदाहरण के लिए,
आपका ऐप्लिकेशन दिए गए uid वाले रिकॉर्ड को मिटाने की कोशिश कर रहा है. हालांकि, अपवाद
नीचे दी गई सेवा की जांच करने पर ऐप्लिकेशन को पता चलता है कि
रिकॉर्ड मौजूद नहीं है.
| इस समस्या से बचने के लिए, यहां कुछ सुझाव दिए गए हैं:
- अपने ऐप्लिकेशन के डेटा स्टोर और Health Connect को नियमित तौर पर सिंक करें.
- अनुरोध से जुड़ी समस्याओं को हल करने के लिए, फिर से कोशिश करने और बैकऑफ़ की रणनीतियां लागू करें.
|
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. 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"]]