Python (at least version 2, I don't have 3) throws a ZeroDivisionError that can be caught.
num = 42
try:
for divisor in (1,0):
ans = num / divisor
print ans
except ZeroDivisionError:
print "Trying to divide by 0!"
produces:
42
Trying to divide by 0!
source
share