faqts : Computers : Programming : Languages : Python : Common Problems : COM

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 26 people (85%) answered Yes
Recently 8 of 10 people (80%) answered Yes

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'
>>>