Entry
How do I get the actual error message from a com_error?
Sep 13th, 2000 06:22
unknown unknown, Alex Martelli
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'
>>>