[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Exceptions in callbacks
From:       Phil Thompson <phil () river-bank ! demon ! co ! uk>
Date:       2001-02-06 11:40:22
[Download RAW message or body]

Pete Ware wrote:
> 
> Bruce Sass <bsass@freenet.edmonton.ab.ca> writes:
> 
> > ...but, if Qt/PyQt does not have a hook into where you want, the only
> > solution may be to expect the unexpected.
> And that is just what I am asking for (unless someone can think of a
> better method).  What I suggested was something like:
> 
>         qt.set_exception_handler (some_function)
> 
> so that some_function() gets called when the PyQt code catches that
> exception.
> 
> It'd be great to be able to do:
> 
>         while 1:
>                 try:
>                         app.exec_loop ()
>                 except:
>                         QMessageBox.warning (parent, 'title',
>                                 'Unanticipated exception')
> 
> though I don't know if Qt's exec() is reentrant and we should probably
> not break old code that doesn't expect the exec_loop() to ever quit.

It should, in theory, be possible to trap the exceptions. If you look at
sipEmitToSlot() in qtlib.cpp (in SIP) you see that it implements the Qt
feature of being able to call a slot with too many arguments. It does
this by detecting the exception, checking what type it is, and re-trying
the call with one less argument. (Python is a lovely language to work
with.) So something could be done.

However, for the reasons you give I'm not so keen on a solution that
would allow your example to work. Out of interest, what happens when you
build your own event loop and use processOneEvent() - ie. use that
instead of exec_loop() in you example?

Having a simple exception handler that at least allowed a dialog box to
be displayed should be Ok.

Phil


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic