exception handling
David Arnold
arnold at dstc.monash.edu.au
Mon May 8 19:10:27 EDT 2000
-->"Jp" == Jp Calderone <exarkun at flashmail.com> writes:
Jp> Is there any way to catch *all* exceptions raised in a
Jp> try/except block *and* get a reference to the exception that was
Jp> raised?
in your except clause, catch exceptions.Exception (the base class for
all exceptions), and grab the instance. from there you can play with
it, like
>>> try:
... raise NameError
... except exceptions.Exception, e:
... print e.__class__
...
exceptions.NameError
>>>
alternatively, try the sys.last_(traceback,type,value) names. these
retain info about the last exception raised.
d
More information about the Python-list
mailing list