Testing whether something is of type Exception

Terry Reedy tjreedy at udel.edu
Sat Jan 26 02:36:57 EST 2008


"John Nagle" <nagle at animats.com> wrote in message 
news:47991a8a$0$36353$742ec2ed at news.sonic.net...
|    How can I tell whether an object is of type Exception?
| At least in Python 2.4, "Exception" is an old-style class, and
| the "type" of Exception objects is "instance".
|
|    Clearly "repr" knows; it returns:
| <exceptions.Exception instance at 0x00A30A80>

Actually, repr does not know.  repr(x) calls x.__repr__.  Each object know 
how to represent itself.

In 2.4 and before, look for 'Exception' in repr(x).






More information about the Python-list mailing list