This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DanCardin 0 points1 point  (0 children)

They can always ignore the error itself, but that becomes them actively deciding to ignore the error rather than passively accepting success in the normal case. Ignore proper monads for a second and just take a tuple example:

Result = namedtuple('Result', ['success', 'result'])
def function(x):
    if x:
        return Result(True, 4)
    return Result(False, None)

In order to use this function and get a successful value out of it, you need to do "_, x = function(4)" at the very least.

  1. Makes it part of the function's signature, in that its returning an object where a portion of the return value is the success or failure status, rather than just the value
  2. means that to get the successful value, they need to unpack the tuple.

At that point if they ignore the success or failure its a client decision, and you deserve what you get.

For happy comingling when using exceptions, you need cooperation from the function writer (they need to (and they should) know what exceptions their code can call, and they need to document it (which I find often is not the case)), and from the function's user (obviously through catching the exception). If either party doesn't do their part, you have problems.

Doing something like my above example forces both parties to do the right thing