请解释为什么异常不会出现在下面示例中的事件循环中。谢谢。
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__()
self.pushButton = QPushButton(self)
self.pushButton.clicked.connect(self.on_click)
self.t1 = 0
def on_click(self):
# ZeroDivisionError
self.t1 = 10 / 0
if __name__ == "__main__":
import logging
logging.basicConfig(level = logging.DEBUG, filename = u"test.log", format = u"%(levelname)-8s [%(asctime)s] %(message)s")
logging.info( u"Start application")
import sys
app = QApplication(sys.argv)
ui = MainWindow()
ui.show()
try:
code = app.exec_()
except Exception as exc:
logging.error(exc, exc_info = True)
logging.info( u"Stop application")
sys.exit(code)