If I'm not sure at something while writing some code I'm trying to read The Zen of Python
once more. For this time those lines hesitate me.
Errors should never pass silently.
Unless explicitly silenced.
At current code I have some functions which might look like this:
def add_v_1(a, b):
return a + b
And all calls for them like:
c = add_v_1(7, [])
Exception for such code will bubble up and caught at upper layers.
But should it be like this?
add_v_1
can raise TypeError
exception and I want to recover from it.
So, the possible call of function would be:
try:
c = add_v_1(7, [])
except TypeError:
print "Incorrect types!"
But for every call, I should do that exception handling. Which looks to heavy.
So, I can do:
def add_v_2(a, b):
try:
return a + b
except TypeError:
print "Incorrect types!"
and a call would be:
c = add_v_2(7, [])
which looks cleaner.
Seems all of those approaches follow The Zen of Python
but which one of them is better choice?