कोड को एक्सेप्शन पकड़ने के लिए निम्न प्रकार से लिखा जा सकता है:
a, b = 5, 0
try:
if b != 0:
print(a/b)
else:
a/b
raise ZeroDivisionError
except Exception as e:
print(e)
हमें निम्न आउटपुट मिलता है:
C:/Users/TutorialsPoint1/~.py integer division or modulo by zero