in c, if i'm not wrong, main function returns 0 if no errors occurred, , different 0 if error occurs.
is appropriate same in python (as long function not have return specific value 1 indicate success/failure); or instead handle exceptions?
in python shouldn't use return value indicate error. should use exceptions.
so, either let exception fired bubble up, or throw new one.
def check_foo(foo): if foo == bar: do_something(args) try: check_foo(...) except someerror: # oops! failure! something_went_wrong() else: # yay! success! everything_went_well() in cases makes sense have functions return boolean, shouldn't used indicate errors.
this typically used in routine checks may true or false, , neither exceptional (i.e. neither an error):
def is_foo(foo): return foo == "foo"
Comments
Post a Comment