On 5/23/07, Sundance <[EMAIL PROTECTED]> wrote:

Arve Knudsen wrote:

> If an exception is raised in the last Python
> layer, it is swallowed by the excepthook and a nice message box pops
> up, BUT once control returns to the first Python layer

Hi again,

In my opinion, the exception hook should never even return. That's what
I meant when I said your application should then close. When you're
dealing with an uncaught exception anyway, something has gone wrong and
it is generally wise not to attempt to keep running, lest data
corruption and bad karma occur, in that approximate order.


You might be right about that the exception hook should not return, at least
now I do some cleaning up when I detect the application is about to
exit. This approach has at least not proved to be a problem before. But, I
don't know whether the exception will be handled before I return control to
the Qt event loop. In the scenario I described in my previous mail, there is
an inner and an outer Python block.  The except hook will be invoked before
control is returned to the first Python block (invoked by the Qt event
loop), and so the first block will never get the chance to handle the
exception.

I am not sure that what you seem to be asking for is at all possible --
it would involve making the Qt event loop aware of Python exceptions, I
think, which doesn't at all sound like good Feng Shui to me.


I was hoping maybe PyQt (with some sip magic?) would be able to trap
exceptions only at the event loop level (in the interface between my code
and the event loop).

If you really, really want to deal with Python exceptions at the
outermost possible level (which will still be inside the Qt event loop
level, mind), then I guess you should make an exception hook that will
store the exception stack in some global variable, push some manner of
custom event to the application's main event queue (or put the
exception stack /in/ the custom event), then return, and have a custom
event handler pull the exception stack off that custom event and only
THEN process it. And quit.


It's possible, certainly, but very brittle since I have to check after
control returns from a Qt method invoked from Python whether an exception
has been detected in the meantime.

Arve
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to