I’m interested in hearing what sort of strategies folks use for handling exceptions in a wxPython program. Is there a best place to trap exceptions and to let the application continue, if possible?
Thanks!
Ron
I’m interested in hearing what sort of strategies folks use for handling exceptions in a wxPython program. Is there a best place to trap exceptions and to let the application continue, if possible?
Thanks!
Ron
GNUmed uses this code:
[gnumed] Contents of /gnumed/gnumed/client/wxpython/gmExceptionHandlingWidgets.py
The top level handler is installed after wxPython
has been initialized.
This traps all so-far unhandled exceptions. We, of course,
also do in-code exception handling where there is something
we can do about the condition.
Karsten
On Thu, Dec 11, 2008 at 08:21:38AM -0600, Ron Kneusel wrote:
I'm interested in hearing what sort of strategies folks
use for handling exceptions in a wxPython program. Is there
a best place to trap exceptions and to let the application
continue, if possible?
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
Once the GUI is actually running and you’re in the event loop, exceptions generally won’t cause the program to actually stop, although they can certainly make large parts of it non-functional. Since I use exceptions for both high-level (i.e. user-created) errors and (unintentionally) for bugs but don’t always know where to expect them, I re-defined sys.excepthook in my custom subclass of wx.App:
class MyApp (wx.App) :
def OnInit (self) :
sys.excepthook = _excepthook
def _excepthook (etype, value, traceback) :
if type is MyError :
else :
(This is basically equivalent to the GNUmed example, I think - just highly condensed.)
On Thu, Dec 11, 2008 at 6:21 AM, Ron Kneusel oneelkruns@hotmail.com wrote:
I’m interested in hearing what sort of strategies folks use for handling exceptions in a wxPython program. Is there a best place to trap exceptions and to let the application continue, if possible?
Once the GUI is actually running and you're in the event loop, exceptions
generally won't cause the program to actually stop, although they can
certainly make large parts of it non-functional. Since I use exceptions for
both high-level (i.e. user-created) errors and (unintentionally) for bugs
but don't always know where to expect them, I re-defined sys.excepthook in
my custom subclass of wx.App:
...
(This is basically equivalent to the GNUmed example, I think - just highly
condensed.)
Correct !
Karsten
On Thu, Dec 11, 2008 at 10:14:18AM -0800, Nathaniel Echols wrote:
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
Ron Kneusel wrote:
I'm interested in hearing what sort of strategies folks use for handling exceptions in a wxPython program. Is there a best place to trap exceptions and to let the application continue, if possible?
For information about why the sys.excepthook hack suggested by others is necessary, please read this page: C++ & Python Sandwich - wxPyWiki
One of the Google Summer of Code projects last summer was changes to allow Python exceptions to propagate through the C++ layers. This hasn't yet been merged to the main source code yet, but it's a possibility in the future.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
Robin, and all who answered, thank you. The explanations make sense and the sys.excepthook hack is working nicely!
Ron
Date: Fri, 12 Dec 2008 10:47:20 -0800
From: robin@alldunn.com
To: wxpython-users@lists.wxwidgets.org
Subject: Re: [wxpython-users] Exception handling strategiesRon Kneusel wrote:
I’m interested in hearing what sort of strategies folks use for handling
exceptions in a wxPython program. Is there a best place to trap
exceptions and to let the application continue, if possible?For information about why the sys.excepthook hack suggested by others is
necessary, please read this page:
C++ & Python Sandwich - wxPyWikiOne of the Google Summer of Code projects last summer was changes to
allow Python exceptions to propagate through the C++ layers. This
hasn’t yet been merged to the main source code yet, but it’s a
possibility in the future.–
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Suspicious message? There’s an alert for that. Get your Hotmail® account now.