[PyQt] Exception within Slot causes Abort

Dave Gradwell davegradwell at yahoo.co.uk
Sun Mar 20 10:55:26 GMT 2016


Appreciated, but if I raise an exception within a slot then Python is aborted; I can't really catch anything 'up chain' and handle it appropriately because the entire Python process is being torn down/aborted. 

But, in the more boring/normal situation, if I raise an exception elsewhere (ie outside of a slot), Python is not aborted, throws the exception 'up chain' and, if not otherwise caught, nicely writes the error out as an error and continues.

There may be ways to defeat qFatal() issuing the Abort (installing a different logger?) but that doesn't seem like the right thing to do. 

Apologies if I am misunderstanding here.  

Dave.

> On 20 Mar 2016, at 10:32, Phil Thompson <phil at riverbankcomputing.com> wrote:
> 
>> On 20/03/2016 10:17 am, Dave Gradwell wrote:
>> In PyQt 5.5.1, raising an Exception within a Slot results in qFatal()
>> calling Abort.
>> That behaviour seems to be documented here, so in a way it seems hard
>> to argue with:
>> http://doc.qt.io/qt-5/exceptionsafety.html#signals-and-slots
>> """Throwing an exception from a slot invoked by Qt's signal-slot
>> connection mechanism is considered undefined behaviour, unless it is
>> handled within the slot"""
> 
> That's referring to C++ exceptions, not Python exceptions.
> 
>> But it worked nicely in 5.4.1 so it seems like a pity.
> 
> An unhandled Python exception is an error.
> 
>> Is there any way of allowing Python Exceptions to be raised within PyQt slots?
>> If not, what is the recommended way of achieving something similar?
> 
> You should be able to use the usual hooks.
> 
> Phil
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list