Lesson 28 of 34
try / except: Errors संभालना
9 min 30 XP
अगर उपयोगकर्ता संख्या की जगह अक्षर टाइप कर दे, तो int() ValueError देता है और प्रोग्राम रुक जाता है। जोखिम वाला कोड try में रखें और समस्या को except में संभालें।
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.हर तरह की error के लिए अलग except लिखें। finally वाला हिस्सा हमेशा चलता है।
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.आप अपनी errors भी उठा सकते हैं: raise ValueError("Age cannot be negative")