[PyQt] Exception within Slot causes Abort
me at the-compiler.org
Sun Mar 20 15:46:41 GMT 2016
* Dave Gradwell <davegradwell at yahoo.co.uk> [2016-03-20 13:20:41 +0000]:
> With PyQt 5.5 the behaviour is inconsistent (consequence depends on context);
> and aborting because you encountered something exceptional seems really quite
> disproportionate to me. And not at all in the spirit of Exceptions as a
> programmer's friend.
I'm not aware of any programming language which has exceptions and
does not abort on an unhandled one.
> > No, it doesn't continue. It quits.
> I am unable to see this behaviour.
> For me, with PyQt 5.4, it continues.
> And to clarify what I mean by 'it continues' I could either say 'it
> doesn't abort' or 'it behaves like a non PyQt Python program would'.
> I am not suggesting it pushes on past the exception or something
> ridiculous like that.
I still don't follow. Any Python code not involving PyQt does *quit*
when there's an unhandled exception:
$ cat exc.py
print("Before an exception")
print("After an exception (not printed)")
$ python exc.py
Before an exception
Traceback (most recent call last):
File "exc.py", line 2, in <module>
ZeroDivisionError: division by zero
Since PyQt 5.5, PyQt does the same.
If you handle the exception, neither a PyQt nor a non-PyQt application
quits - adopted from your example:
$ cat exc2.py
from PyQt5 import QtCore, QtWidgets
app = QtWidgets.QApplication(sys.argv)
timer = QtCore.QTimer()
$ python exc2.py
So really the only thing which changes is that PyQt 5.5+ does not
silently ignore unhandled exceptions anymore, like *everything else
does*. How is this not consistent?
> If so, what construct can I use to regain the nice behaviour of PyQt 5.4?
You can do:
sys.excepthook = traceback.print_exception
But again, you'll have undefined behaviour on exceptions inside C++
> Also, the Abortion is in full swing by this time. I.e. We're doomed. No?
If you have an unhandled exception, you're kind of doomed anyways?
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: Digital signature
More information about the PyQt