On 2005-02-12, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> If a function that normally returns N values raises an exception, what
> should it return?

Maybe it shouldn't return anything but instead of cathing the
exception it should let the caller handle it.

> 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.

what about the following.

def foo(x):

  # code setting y and z
  return x,z

try
  y,z = foo(x)
except ... :
  # Handle errors.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to