Dumb idea number forty-two:
if __debug__:
# Don't catch exceptions during development
app = App(0)
app.MainLoop()
else:
# Catch all exceptions when in production
try:
app = App(0)
app.MainLoop()
except: # Catch all exceptions (or will it?)
# Do something to log the exception for
# the user who won't think to write it down
# or when there's no console for output
pass
Would this work? Bad idea? Some better way?
Thanks,
Michael Hipp
Heber Springs, Arkansas, USA
Michael Hipp <Michael@Hipp.com>:
[snip]
except: # Catch all exceptions (or will it?)
You *could* use
except Exception, e:
so you could check e for further information.
[snip]
Would this work? Bad idea? Some better way?
It will, of course, also catch (and ignore) such things as Ctrl-C and
sys.exit()...
···
--
Magnus Lie Hetland
http://hetland.org
That isn't a bad route, though I suggest:
except Exception, ex: pass
Or better yet, put in handlers so ^C and sys.exit still
work.
except KeyboardInterrupt, ex: raise
except SystemExit, ex : raise
except Exception, ex : pass
For many applications there is a better way: Provide your
own exception handler function and replace sys.excepthook
with it. I use this a lot with GUI applications to provide
my own exception reporting mechanism (such as a GUI window).
This also allows user-feedback of errors with no extra code
(report the string in a small dialog, and have another
mechanism to view the full error if needed for developers).
Just remember the sys.excepthook routine cannot interact
with the GUI, it must populate a queue which is watched by
an OnIdle event function....
--David
···
On Sat, Aug 27, 2005 at 01:10:43PM -0500, Michael Hipp wrote:
except: # Catch all exceptions (or will it?)
# Do something to log the exception for
# the user who won't think to write it down
# or when there's no console for output
pass
Would this work? Bad idea? Some better way?
actually this is a reinvention of the wheel:
Use something like:
if __debug__:
# Don't catch exceptions during development
app = App(0)
app.MainLoop()
else:
# Catch all exceptions when in production
app = App(1, "log.txt")
app.MainLoop()
actually replace log.txt with something from the user's home
more info here:
http://www.wxpython.org/docs/api/wx.App-class.html
use this for unexpected stuff and the logging api from python for known output (replace print statements with log.debug("bla bla") or log.error or whatever seams sane)
Peter.
···
On Sat, 27 Aug 2005 21:10:43 +0300, Michael Hipp <Michael@Hipp.com> wrote:
Dumb idea number forty-two:
if __debug__:
# Don't catch exceptions during development
app = App(0)
app.MainLoop()
else:
# Catch all exceptions when in production
try:
app = App(0)
app.MainLoop()
except: # Catch all exceptions (or will it?)
# Do something to log the exception for
# the user who won't think to write it down
# or when there's no console for output
pass
Would this work? Bad idea? Some better way?
Peter Damoc wrote:
# Catch all exceptions when in production
app = App(1, "log.txt")
app.MainLoop()
actually replace log.txt with something from the user's home
more info here:
http://www.wxpython.org/docs/api/wx.App-class.html
Thanks for this and for all who replied; this looks like a more "approved" solution.
I've largely taken the wxApp class for granted. At least now I see it in a bit more depth.
Michael