Python

try / except

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

try/except është mënyra si Python-i kap gabimet që të mos rrëzohet programi. Kodin e rrezikshëm e vë te try, dhe te except shkruan çfarë ndodh nëse diçka shkon keq — p.sh. kur përdoruesi shkruan tekst në vend të numrit.

EnglishEN

try/except is how Python catches errors so the program doesn't crash. You put the risky code in try, and in except you say what happens if something goes wrong — like when the user types text instead of a number.

Si ta mendosh

Si portieri pas mbrojtjes: nëse topi kalon mbrojtësit, ai është aty ta kapë para se të bëhet gol.

Lexoje në anglisht

Like the goalkeeper behind the defence: if the ball gets past the defenders, they're there to catch it before it's a goal.

Shembull kodipython

try:
    mosha = int(input("Sa vjeç je? "))
except ValueError:
    print("Shkruaj një numër, të lutem!")

Terma të lidhur