[Tutor] functions: use return or exceptions?
Wayne Werner
waynejwerner at gmail.com
Thu Sep 23 21:47:21 CEST 2010
On Thu, Sep 23, 2010 at 2:32 PM, Alex Hall <mehgcap at gmail.com> wrote:
> Hi all,
> A general coding question: is it better to use return(False) (or 0, or
> -1, or whatever) or to raise whateverError("oops")? Are there cases
> for each?
It depends on your prevailing philosophy - if you like the EAFP that
prevails in python, it's better to raise an error. Usually that indicates
that something has failed.
OTOH, a lot of people feel that using exceptions as control flow is bad
practice - they're exceptional so they should only arise in exceptional
case.
There may be performance issues, though I'm not familiar enough with that
yet.
just my two bits,
-Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100923/850c35d0/attachment.html>
More information about the Tutor
mailing list