Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel:
pywintype
No-one has yet mentioned the strerror
attribute of the pywintypes.com_error Exception. This returns the result of FormatMessage
for the error code. So instead of doing it yourself like this
try:
[whatever code]
except pythoncom.com_error as error:
print(win32api.FormatMessage(error.excepinfo[5]))
You can just do this:
try:
[whatever code]
except pythoncom.com_error as error:
print(error.strerror)
Note it will return None
if you have a non-standard HRESULT
:(