How do I know all thrown exceptions of a function?

Steve Williams sandj.williams at gte.net
Sun Jan 21 12:59:49 EST 2001


Fredrik Lundh wrote:

> 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...
>
> Cheers /F

Now, now.  I raised a similar point about 'from ftplib import FTP' exceptions a
few weeks ago and was told RTFM.

Packaging my code for production use, adding try/excepts and testing by forcing
failures,  I found I couldn't catch ftplib exceptions, although I copied the
example shown in Beazley and in the ftplib code itself.

Catching exceptions thrown by imported classes is not easy, simple or clear,
IMHO.  The  solution requires a technique (adding the exception name to the
import statement) that is not common in Python documentation or examples.

If the imported class throws a number of different exceptions, is there a tuple
defined with the exception names and can we reference this tuple in the import
statement and reference the tuple members in our 'except' statements, or must we
name each exception separately in the import?

On into the darkness. . .





More information about the Python-list mailing list