How do I know all thrown exceptions of a function?

Carel Fellinger cfelling at iae.nl
Mon Jan 22 17:39:30 EST 2001


Steve Williams <sandj.williams at gte.net> wrote:
...
> 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.

I'm not sure  I fully understand you, but something like the following
seems common in Python:

Module somelib:

   class Error(Exception):
	pass

   def somefunc():
       '''does something
          beware, could raise Error
       '''
       raise Error


Module MyProg:

   import somelib

   try:
	somelib.somefunc()
   except somelib.Error:
        'do something about it'
-- 
groetjes, carel



More information about the Python-list mailing list