win32all - which exception?

Mark Hammond MarkH at ActiveState.com
Sat Jun 23 23:10:52 EDT 2001


Robert Pyron wrote:

> I'm using win32 extensions to enumerate top-level windows. 
> For each window, I call win32gui.GetParent(). 
> If the window has no parent, the function raises an exception.
> So, I have two questions:
> 
> 1. What exception is raised by this function? I'm using 
>    try:/except: to catch all exceptions, but I would like to
>    be more specific.
> 
> 2. In general, for other win32 functions, how can I tell which
>    exception is being raised?

The win32 extensions generally raise the _same_ exception for all 
functions.  However, this exception has a number of aliases.

eg, if using win32gui, then win32gui.error is probably good style. 
However, almost all modules ".error" attribute is identical to the 
others.  The "canonical" exception is pywintypes.error (as it is defined 
in this DLL, which is used by all win32 exceptions.)

eg:
 >>> win32gui.error
<class pywintypes.api_error at 002F9D44>
 >>> win32api.error
<class pywintypes.api_error at 002F9D44>
 >>> pywintypes.error
<class pywintypes.api_error at 002F9D44>
 >>>

ie, all the exact same error.

Mark.




More information about the Python-list mailing list