Hi,
I'd like to store uncaght exception traceback inside a log file.
It's easy with the traceback module, but how do you catch exceptions that come from one of the WxPython frame window?
Thanks for the help
Hi,
I'd like to store uncaght exception traceback inside a log file.
It's easy with the traceback module, but how do you catch exceptions that come from one of the WxPython frame window?
Thanks for the help
Hi Pierre,
I'd like to store uncaght exception traceback inside a log file.
It's easy with the traceback module, but how do you catch exceptions
that come from one of the WxPython frame window?
Take a look at the logging module that is standard in Python 2.3, but
must be separately imported in 2.2 and before. As far as I know any
exception is caught there, and can then be processed in any manner
conceivable.
Hope this helps,
Regards,
Dick Kniep
Robin Dunn wrote:
Pierre Rouleau wrote:
Hi,
I'd like to store uncaght exception traceback inside a log file.
It's easy with the traceback module, but how do you catch exceptions that come from one of the WxPython frame window?When you call MainLoop and then event handlers or other callbacks are invoked, and then you call other wx methods, which can then cause other callbacks, etc, etc, then you end up with a multi-layered C++/Python sandwich on the call stack. When an exception happens in a Python layer there is not currently any safe way to propogate that exception across the C++ layer to the next Python layer up the stack, so the C++ layer will instead check if there was an exception and just call PyErr_Print() if there was. So if you want to catch exceptions you need to do it within the same Python layer where it happens, before the event handler or callback returns to the C++ layer.
That makes sense. It's what I was afraid of. This means that I would have to write exception catching code in every event handler?
Normally I would'nt have any problem with this since a console window would show all the traceback info. But when I package the application with the McMillan installer with the 'no console' option, the resulting application sometimes does not start. I was hoping to find a way to record exceptions that occur anywhere to log them to a file. I don't really want to instrument all the code with exception catching for that.
If there is a better way, let me know.
Thanks!
Erik Westra wrote:
Hi Pierre,
A quick question for you:
Normally I would'nt have any problem with this since a console window would show all the traceback info. But when I package the application with the McMillan installer with the 'no console' option, the resulting application sometimes does not start. I was hoping to find a way to record exceptions that occur anywhere to log them to a file. I don't really want to instrument all the code with exception catching for that.
If there is a better way, let me know.
Why don't you simply redirect standard error to a file (or file-like device like a StringIO object)? I've redirected both sys.stdout and sys.stderr to a text file, and my app now writes the errors to that file rather than writing to the console window (or crashing if the app has been built and has no console window).
Quick answer:
Obviously, I should have been sleeping more, worrying less and using Pythonic simple things!
For some reason, i was trying to catch exceptions to restart some portions of the software as well as logging errors and i got on a slope...
Thanks for the wake up call!