I’m writing a little debug app for a bit of kit we’re developing and I’d like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way of effectively wrapping a wxPython app to catch any and all unhandled exceptions that would cause the app to crash?
Ideally I’d want to capture all output (not just errors) and log it to a file. Any unhandled exceptions ought to log to the current file and then allow the exception to pass on as per usual (i.e. the logging process ought to be transparent).
I’m sure someone must have done something along these lines before, but I’ve not managed to turn up anything that looks useful via google.
For logging standard output, you can use a stdout wrapper, such as this one:
You then have to initialize it in your main Python file (the one that runs everything):
As to logging exceptions, the easiest thing to do is to wrap
MainLoopmethod of wx.App in a try..except, then extract the exception information, save it in some way, and then re-raise the exception throughraise, e.g.: