com_error

Alex Martelli aleaxit at yahoo.com
Sat Sep 9 18:48:20 EDT 2000


<ramesh4954 at my-deja.com> wrote in message
news:8pe2u8$9sl$1 at nnrp1.deja.com...
> How do I get the actual error message from a com_error? When I try to
> print the details I get the following :
> <pywintypes.com_error instance at 902e60>
>
> Any help would be appreciated. Thanks

Use the .args member of the error object.  Example:

>>> import pywintypes
>>> import win32com.client
>>> try: foo=win32com.client.Dispatch("Not.There")
... except pywintypes.com_error, erob: print 'caught'
...
caught
>>> erob
<pywintypes.com_error instance at 14ca800>
>>> print erob
(-2147221005, 'Invalid class string', None, None)
>>> dir(erob)
['args']
>>> erob.args
(-2147221005, 'Invalid class string', None, None)
>>> erob.args[0]
-2147221005
>>> erob.args[1]
'Invalid class string'
>>>


Alex






More information about the Python-list mailing list