Modules implicitly exposing exceptions from other modules

Skip Montanaro skip at
Wed Feb 16 10:04:38 EST 2000

[ jumping in a bit late on this thread... ]

    Randall> No, you miss the point of my example.  I didn't say "socket", I
    Randall> said "Socket".  NNTP could be built on Socket, or FastSockets,
    Randall> or TLI, or MasGreatestSocketModule, all of which could have a
    Randall> different exception structure.

I believe if a higher level module relies on a lower level module to
implement some of its functionality, the higher level module should catch
the lower level module's exceptions and transmogrify them into something
higher level.  I see two reasons for this:

    1. Randall's argument that you could swap out the lower level module for
       something else.  This provides an increased measure of independence
       from the lower level module of the application code that calls the
       higher level module.

    2. There is often extra information available to the higher level module
       (file names, user input values, attribute values) that would be
       useful to someone debugging the traceback.  Letting the lower level
       exception pass through "unadulterated" ignores this useful
       information.  More accurate information ==> better error diagnostics
       ==> faster debugging.

Skip Montanaro |
skip at |
"Languages that change by catering to the tastes of non-users tend not to do
so well." - Doug Landauer

More information about the Python-list mailing list