How do I know all thrown exceptions of a function?

Steve Williams sandj.williams at gte.net
Mon Jan 22 22:36:09 EST 2001


Carel Fellinger wrote:

> Steve Williams <sandj.williams at gte.net> wrote:
> ...
> > Ah yes, but ftplib (and the example in the code and in Beazley) does the
> > following:
>
> ...example snipped
>
> My point was that instead of
>
> >    from somelib import somefunc
>
> you should use
>
>      import somelib
>
> then the following would work
>
> >    try:
> >         somelib.somefunc()
> >    except somelib.myError:
> >         'do something about it'
>
> --
> groetjes, carel

Well, yes.  But that brings in all the other cruft in somelib, when we just
wanted somefunc.

We could also use

    from somelib import *

<1.0E-5 wink>

Now we are getting dangerously close to saying something like "don't ever use

    from somelib import somefunc

because we don't know the exceptions or how the exceptions are defined."

The original point of the thread, IIRC.





More information about the Python-list mailing list