[PyQt] Exceptions in Python Implementations of Virtuals

Phil Thompson phil at riverbankcomputing.com
Wed Oct 1 09:31:26 BST 2014


On 01/10/2014 9:05 am, Florian Bruhin wrote:
> * Phil Thompson <phil at riverbankcomputing.com> [2014-10-01 08:53:10 
> +0100]:
>> Of course qFatal() only aborts the application if you are using the 
>> default
>> message handler. There is nothing to stop you doing exactly what you 
>> would
>> do with sys.excepthook and you would also catch any calls from within 
>> Qt.
> 
> If this can easily be overrided by setting sys.excepthook, big +1 for
> it from me.
> 
> Applications with a custom exception handler won't break, and
> applications without a handler (which are already broken) will fail
> loudly rather than silently, just like anything else in Python.
> 
> Still I think qFatal should be used (even when sys.excepthook is set)
> in the few places known to cause segfaults otherwise. An exception
> message and qFatal is still better than a segfault without any message
> (and random coredump).

So...

For all exceptions raised by virtual reimplementations (and slots 
connected to signals) PyQt will invoke an error handler that will check 
if sys.excepthook has been modified. If it has been modified then it 
does nothing, otherwise it calls qFatal(). That should mean that "good" 
applications continue to work without changes.

It will be possible to specify (in the .sip file) that an individual 
virtual must not raise an unhandled exception. This would be implemented 
by explicitly calling abort() after calling the error handler.

Phil


More information about the PyQt mailing list