I often find myself returning a boolean from a method, that's used in multiple locations, in order to contain all the logic around that method in a single place. All the (internal) calling method needs to know is whether the operation was successful, or not.I'm using Python but the question isn't necessarily specific to that language. There are only two options I can think ofRaise an exception, though the circumstances are not exceptional, and remember to catch that exception in every place the function is calledReturn a boolean as I'm doing.This is a really simple example that demonstrates what I'm talking about.import osclass DoSomething(object):    def remove_file(self, filename):        try:            os.remove(filename)        except OSError:            return False        return True    def process_file(self, filename):        do_something()        if remove_file(filename):            do_something_else()Although it's functional, I really dislike this manner of doing something, it smells, and can sometimes result in a lot of nested ifs. But, I can't think of a simpler way.I could turn to a more LBYL philosophy and use os.path.exists(filename) prior to attempting deletion but there's no guarantees the file won't have been locked in the meantime (it's unlikely but possible) and I still have to determine whether the deletion has been successful or not.Is this an acceptable design and if not what would be a better way of designing this?
Returning a boolean when success or failure is the sole concern
design patterns;python;boolean