Starlit Daily

📚 › Python: the friendliest first language

13. Handling errors with try and except

ستتم ترجمة هذا المقال تلقائيًا. يُعرض بالإنجليزية حاليًا.

try runs code that might fail, and except handles the error. Without it, a single mistake stops the whole program.

Read the error message: it names the problem and the line.

عرض المثال

try:
    print(10 / 0)
except ZeroDivisionError:
    print("Cannot divide by zero")

✍️ دورك الآن

Use try and except: in try divide 1 by 0, in except print Cannot divide.

← العودة إلى الدورة