win32api exception names?

G. Willoughby thecalm at NOSPAM.btinternet.com
Tue Jul 31 07:40:50 EDT 2001


could you please explain the code needed a little better? sorry!

if i use something like this:

except win32api.api_error, info:
    win32api.MessageBox(0,"File can not be opened, right double click to
open\nthe file's directory.", appName, 0, 0)

then i get: AttributeError: 'win32api' module has no attribute 'api_error'

any ideas?

G. Willoughby

"David Bolen" <db3l at fitlinxx.com> wrote in message
news:uhevt6hsy.fsf at ctwd0143.fitlinxx.com...
> "G. Willoughby" <thecalm at NOSPAM.btinternet.com> writes:
>
> > I'm using this function to open a file listed in a Tkinter Listbox
widget,
> > but i've run into some problems. First when i double click on .htm files
> > listed they work perfectly, opening in Explorer, But when i double click
on
> > .txt files i get this error:
> >
> > Exception in Tkinter callback
> > Traceback (most recent call last):
> >   File "c:\program files\python\lib\lib-tk\Tkinter.py", line 1285, in
> > __call__
> >     return apply(self.func, args)
> >   File "D:\Backup\Python Programs\PyFind\PyFind.py", line 61, in
executeFile
> >     win32api.ShellExecute(0, "open" ,
str(resultPane.get(ACTIVE)),"","",1)
> > api_error: (31, 'ShellExecute', 'A device attached to the system is not
> > functioning.')
> >
> > i'm trying to handle this exception, but being new to them i dunno what
> > exception is being raised, the 'except EnvironmentError:' line really
isn't
> > getting it. any ideas?
>
> I can't necessarily address why your code is returning that specific
> exception (perhaps a bad path?), but each of the PythonWin modules all
> raise an api_error exception for any general Win32 errors.  The first
> element in the instance data tuple will be the underlying Win32 error
> code (31 in this case is ERROR_GEN_FAILURE), then the failing function
> call, and finally a textual description.
>
> So if you want to catch these in your exception handler, you can use:
>
>     except win32api.api_error, info
>
> and then if necessary, inspect the actual Win32 API error code (in
info[0]).
>
> --
> -- 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