[PyKDE] Exceptions in callbacks

Bruce Sass bsass at freenet.edmonton.ab.ca
Sat Feb 3 18:42:17 GMT 2001


On 3 Feb 2001, Pete Ware wrote:

> Perhaps I oversimplified.

Naw, you're just looking for a different implementation.

> Imagine the user pushing on some button in the UIF and for whatever
> reason (permission denied, coding error (gasp), etc) some exception is
> raised.

You are expected to know when an error could occur, and wrap the
problem command(s) up in try:/except:...  an unhandled error gets
passed up the scope levels until a handler is found (the except:
clause), if none if found the program terminates.


> Right now, PyQt internally catches the exception -- which is
> great as the Qt event loop continues executing which is much, much
> better than the application dying.
>
> What I'd like to be able to do is to tell the PyQt code:
>
>         qt.set_exception_handler (some_function)
>
> so when any exception reaches the PyQt event loop, some_function()
> gets called.

I think you will find the Python way more flexible once you get your
head around it.  You get to handle the error within the context it
occured, which lets you fix it on the fly (if possible) and resume
with the program.


- Bruce





More information about the PyQt mailing list