def log_uncaught_exceptions(ex_cls, ex, tb):
text = '{}: {}:\n\n'.format(ex_cls.__name__, ex)
import traceback
text += ''.join(traceback.format_tb(tb))
QMessageBox.critical(None, 'Ошибка!', text)
quit()
sys.excepthook = log_uncaught_exceptions