error code

ferreira jorge dark_phenix_98 at yahoo.fr
Wed Jul 24 11:27:23 EDT 2002


In your example you write the Exception code .

for example :
try :
    server = smtplib.SMTP('XXXXXXX')
except :
    print "error : %s --> %s " % ( sys.exc_value , sys.exc_type)

If I put a bad host , I have the error : "error : host not found -->
socket.error"

I suppose that the error "host not found" have a caracteristic number .
how can I get it ?


"Mark McEahern" <marklists at mceahern.com> a écrit dans le message de news:
mailman.1027523168.10025.python-list at python.org...
> > I want to get the code of an error .
> >
> > how can I do that ?
> >
> > With "sys.exc_value" and "sys.exc_type" I have a String .
> > But I want a Integer
>
> This probably isn't what you want, but given the vagueness of your
question,
> how the heck would I know that?  <wink>
>
> class MySpecialError(Exception):
>
>   code = 100
>
> try:
> raise MySpecialError
> except Exception, e:
> if hasattr(e, "code"):
> print "Code: %d" % e.code
>
> // mark
>
> -
>
>





More information about the Python-list mailing list