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")

Challenge

+30 XP

input() ഉപയോഗിച്ച് ഒരു value വായിക്കൂ. പൂർണ്ണസംഖ്യയാണെങ്കിൽ അതിന്റെ ഇരട്ടി print ചെയ്യൂ. അല്ലെങ്കിൽ Invalid print ചെയ്യൂ. try / except ഉപയോഗിക്കൂ.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.