B
beliavsky
If a function that normally returns N values raises an exception, what
should it return? N values of None seems reasonable to me, so I would
write code such as
def foo(x):
try:
# code setting y and z
return y,z
except:
return None,None
y,z = foo(x)
If I try to use y or z inappropriately when they are None, the program
will stop. An alternative is to return an error flag in addition to y
and z from function foo and check the value of the error flag in the
calling program. This seems a bit awkward.
should it return? N values of None seems reasonable to me, so I would
write code such as
def foo(x):
try:
# code setting y and z
return y,z
except:
return None,None
y,z = foo(x)
If I try to use y or z inappropriately when they are None, the program
will stop. An alternative is to return an error flag in addition to y
and z from function foo and check the value of the error flag in the
calling program. This seems a bit awkward.