[wxPython-users] Better exception handling
Gre7g Luterman
hafeliel at yahoo.com
Thu Jun 28 08:07:06 PDT 2007
--- Jorgen Bodde <jorgen.maillist at gmail.com> wrote:
> Hi All,
>
> I love wxPython! One thing that worries me for my
> end-users is the
> inability to see potential errors. When my GUI app
> is ran from a
> console window, the exception is thrown in there.
> But when somethign
> happens and the console window is not there, I would
> like to see an
> error window similar to the stack walker. The way it
> is now, errors
> and exceptions are eaten if I rename my app's
> extension to myapp.pyw
Well, I can't speak for everyone, but here's what I do
when developing a wxPython app. Feel free to tell me
if there is a better way:
[1] I write my code in the usual way and keep an eye
out for the obvious places that errors will get thrown
(file errors, communication errors, etc.) and catch
these with try/except statements. I put up Dialogs to
warn users about what is going on.
[2] I debug my code with the console going so I can
see what exceptions get thrown. Then I fix my bugs
and catch any exceptions that I had not originally
planned for.
[3] Once I think my code is pretty stable, I add the
following to my main program:
sys.stderr = open(Const.ErrLog, "w")
That way if there are any errors that dump to stderr,
they will get tossed in a file. When a user calls me
to complain that something is not working right, I
have them replicate the problem and then e-mail me the
log file so I can see the traceback.
I suppose it would be possible to replace a file with
a class that brings up dialog, but before you write
that, I recommend that you:
[1] Keep logging stuff to a file so that when users
call, they don't have to read off lines and lines of
traceback to you.
[2] Remember that stderr text can be generated in
threads other than the main thread, so be sure you
create a custom event to signal the display of an
exception instead of trying to do it in your new
stderr gathering class.
Good luck,
Gre7g
____________________________________________________________________________________
Don't get soaked. Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather
More information about the wxpython-users
mailing list