How do I know all thrown exceptions of a function?

Christian Tanzer tanzer at swing.co.at
Tue Jan 23 03:11:23 EST 2001


Donn Cave <donn at u.washington.edu> wrote :

> Quoth Randall Hopper <aa8vb at yahoo.com>:
> | Fredrik Lundh:
> || Sean Reifschneider wrote:
> ||> Yeah, I suppose so.  I don't think you should *HAVE* to review the code of
> ||> the libraries you call, AND *EVERYTHING* that *THEY* call.  It's not an
> ||> effective use of my time...
> ||
> || yeah, and what's worse, having to *TEST* your code before
> || shipping just sucks...
> |
> | Like Steve, I think this is a bit too harsh.  What exceptions a public API
> | can throw is part of its interface, just like parameters and return values.

It is harsh. And testing certainly isn't an effective way of
finding out what exceptions can occur.

> | Groveling through library code for rare exception conditions (initially,
> | and for each dependency version update) isn't a productive use of a
> | developer's time.
> 
> Certainly not, and to me exception handling feels like the most
> unfinished part of Python.  Unfortunately I don't have any real
> ideas about it, I just find exception handling relatively error
> prone when it should be the opposite.

It's not the exception handling per se. IMHO, one of the problems is
that the exception hierarchy does not make any distinction between
exceptions indicating errors and exceptions indicating things like
KeyboardInterrupt or SystemExit which aren't errors.

If an application wants to avoid dying even in the presence of bugs it
must contain a catch-all clause somewhere. Yet, it certainly doesn't
want to catch SystemExit there, and it might not want to catch
KeyboardInterrupt either. This leads to code like:

    try :
        ...
    except (SystemExit, KeyboardInterrupt), exc :
        raise exc
    except :
        ...

Yuck.

BTW, silently dropping the exception in the catch-all handler is of
course not recommended.

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list