Which exception has been used? (was: Which exception to use?)

Delaney, Timothy tdelaney at avaya.com
Fri Jan 31 01:39:57 CET 2003


> From: Laura Creighton [mailto:lac at strakt.com]
> 
> > Suppose, as is always true, though, that I'm dealing
> > with modules not under my control.  How do I catch
> > "other"?  There must be something I'm missing about
> > the new type and exception systems, 'cause I don't 
> > see a Pythonic way to write
> >   ....
> >   except OTHER, e:
> >       # The foreign code threw an exception of
> >       #    a type I don't recognize, but I need
> >       #    to process/log/... 'e'.
> >       cope(e)
> > Yes, I can write
> >   ....
> >   except:
> >       cope()
> > but then I've lost the information I want in 'e'.
> 
>  It is sitting around in  sys.exc_info(). Grab it before 
> another exception
>  happens. 

Note as well, that sys.exc_info() is thread-safe - if an exception occurs on
another thread it will not affect the result. sys.exc_info() will only be
overwritten by an exception on the same thread.

Tim Delaney





More information about the Python-list mailing list