Safe division
Python Exceptions
try / except
Flowchart (ISO 5807)
Source code
def safe_div(a, b):
try:
return a / b
except ZeroDivisionError:
return 0 try / except
def safe_div(a, b):
try:
return a / b
except ZeroDivisionError:
return 0