Pythonic API design: detailed errors when you usually don't care

Aahz aahz at pythoncraft.com
Mon Oct 2 14:09:12 EDT 2006


In article <1159807538.579131.198670 at e3g2000cwe.googlegroups.com>,
Simon  Willison <swillison at gmail.com> wrote:
>
>try:
>  do_something()
>except HttpError:
>  # An HTTP error occurred
>except ApplicationError:
>  # An application error occurred
>else:
>  # It worked!

Use a similar but different idiom:

try:
    do_something()
except DoSomethingError:
    # handle error

IOW, your do_something() function maps all expected errors to
DoSomethingError (or at least to a series of related exceptions that are
all subclasses of DoSomethingError).
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"  -- www.nancybuttons.com



More information about the Python-list mailing list