Just looking for opinions on which is the best way to use exceptions?
Should the exception handling go inside the function or should it go outside the function when you actually call the function. For example, we could have the following function:
def divideMe(a,b):
return a/b
This function is risky because there is a chance that if the calling program passes a value of 0 in for the argument b then the function would divide by zero and an exception would be raised. So the question is should you put the exception handling inside the function and handle it like this:
def divideMe(a,b):
try:
return a/b
except Exception:
return 0
OR should the calling program catch and handle the exception, like this:
try:
result = divideMe(x,y)
except Exception:
print("You entered 0 in for denominator")