[PyKDE] starting a new PyKDE project
jbublitz at nwinternet.com
Wed Jan 17 20:23:59 GMT 2007
On Wednesday 17 January 2007 09:22, Joseph Rawson wrote:
> I do have a quick question. Is it possible to display a KMessageBox.error
> on any exception that is raised while the application loop is running? I
> know that I can make my own exception classes and have them make the
> dialogs, but this only helps when I expect an error.
Look at sys.excepthook in the sys module in the Python Library Reference
docs.. Define an exception handler:
# 3 arguments required
def yourExceptionHandler (a,b,c):
print "*** got exception ***"
and beofre starting the event loop do:
sys.excepthook = yourExceptionHandler
The sys..excepthook method (which is now pointed to "yourExceptionHandler")
gets all unhandled exceptions.
You could, for example, define a method that pops up the KMessageBox as part
of your KMainWindow subclass, and then call that method from
An easy test is to define a button that attempts division by zero when clicked
- "yourExceptionHandler" should get called when you click the button, and
whatever you code that to do should then happen.
More information about the PyQt