How do I get info on an exception ?
ianb at colorstudy.com
Fri Jul 18 08:39:39 CEST 2003
On Fri, 2003-07-18 at 01:33, Frank wrote:
> Using Python 2.2.2,
> I want to catch all exceptions from "socket.gethostbyaddr(ip)"
> >From IDLE, I can generate:
> >>> socket.gethostbyaddr('1.2')
> Traceback (most recent call last):
> File "<pyshell#28>", line 1, in ?
> herror: (11004, 'host not found') <=== what I want when I catch
> When I run this code:
> hostname, aliases, hostip = socket.gethostbyaddr(ip)
> return (hostip, hostname)
> print sys.exc_info()
> print sys.exc_type
do exceptional stuff...
except Exception, e:
print e.args, dir(e)
Probably that information is just in e.args, but you can add other
attributes to exceptions, any of which should be revealed by dir(e).
Exceptions are poorly documented, so I don't know where that might be
More information about the Python-list