how do i catch pywintypes.api_error?

David Bolen db3l at fitlinxx.com
Fri Oct 5 13:14:22 EDT 2001


"John S. Yates, Jr." <john at yates-sheets.org> writes:

> Is there anyway to write an except handler that will
> catch only api_error?  Alternatively, within a handler
> can I determine whether or not I have an api_error?

It can be a little confusing at first.  The actual error object that
is used during exceptions is normally named "error" within the module
that you are using.  However, when it represents itself as a string it
always displays pywintypes.api_error.

For example:

    >>> import win32file
    >>> print win32file.error
    pywintypes.api_error

So if for example, you've imported win32file and are working with that,
put the except clause for "win32file.error".

If you're using multiple modules, it may be possible to use any of
their error classes, but I'm not positive.  I normally just stick with
the module within which I'm making the API call.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list