[wxPython-users] Better exception handling

Josiah Carlson jcarlson at uci.edu
Thu Jun 28 08:25:18 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
> ..
> 
> I would not like that as it leads to undesired behaviour and people
> not seeing an error and think a particular button does not do anything
> can cause more harm then showing an error dialog. Also if there is no
> feedback, not many people will file a report.
> 
> Is there a way to get errors back from python's exceptions when there
> is no console window??

You can write an 'exception hook' function, and assign it to
sys.excepthook .  That will allow you to capture only exceptions.

As an alternative:

Step 1:
    a = wx.App(0)

Step 2:
    sys.stdout = sys.stderr = something

Where 'something' is some sort of logging/display class for handling
exceptions/output.


 - Josiah





More information about the wxpython-users mailing list