Lesson 28 of 34
try / except: பிழைகளைக் கையாளுதல்try / except: Handling Errors
9 min 30 XP
பயனர் எண்ணுக்குப் பதிலாக எழுத்தை type செய்தால் int() பிழை (ValueError) தரும், program நின்றுவிடும். try உள்ளே ஆபத்தான code-ஐ வைத்து, except-ல் பிழையைச் சமாளிக்கலாம்.
If a user types letters instead of a number, int() raises a ValueError and the program stops. Put risky code in try and handle the problem in except.
Example: edit me and press Run
Press Run to see the result here.வெவ்வேறு பிழைகளுக்கு வெவ்வேறு except எழுதலாம். finally பகுதி எப்போதும் இயங்கும்.
Write a separate except for each kind of error. The finally part always runs.
Example: edit me and press Run
Press Run to see the result here.raise மூலம் நீங்களே பிழையை எழுப்பலாம்: raise ValueError("Age cannot be negative")
You can raise your own errors: raise ValueError("Age cannot be negative")