[python-win32] Friendlier pywintypes.com_error messages

Tim Roberts timr at probo.com
Fri Aug 8 23:44:12 CEST 2008


Brad Johnson wrote:
> I am using pywin32 scripting as a client to my C++ COM application. Many of my
> functions in C++ are returning errors such as E_FAIL, E_POINTER, E_INVALIDARG,
> etc...
>   

...which are, after all, just numbers.  E_FAIL is 0x80004005, which 
shows in the exception report as -2147467259.  E_POINTER is 0x80004003.  
E_INVALIDARG is 0x80070057.

> However, the error message in Python is often cryptic such as a simple
> "Exception occurred" with the error code.
>   

The code is buried in that report.  One trick is not to look at the 
first large negative number (which is usually the generic "an error 
occurred" error), but instead look for the second large negative number:

 >>/ com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0,
/ >>/ -2147467259), None)
/

Here, -2147352567 is DISP_E_EXCEPTION, which means "exception 
occurred".  The real error code is -2147467259, which is 0x80004005, 
which is E_FAIL.

> I suppose I could handle these exceptions and somehow post my own strings as the
> error message, but I figured I'd ask if there is a list of supported error codes
> that give more information.
>   

Not sure what you mean by "supported error codes".  There are HRESULT 
error numbers spread all over the include files in the Platform SDK.  
The most common (like the three you mentioned) are in WinError.h.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list