Exemple #1
0
def test_exceptiondialog():
    def f(depth, verbose=False):
        if verbose:
            print(1 / depth)
        else:
            1 / depth
        return f(depth - 1, verbose)
    try:
        f(4)
    except Exception:
        app = QtWidgets.QApplication(sys.argv)
        d = GSDViewExceptionDialog()
        #d = ExceptionDialog()
        d.show()
        app.exec_()
    print('done.')
Exemple #2
0
def test_exceptiondialog():
    def f(depth, verbose=False):
        if verbose:
            print(1 / depth)
        else:
            1 / depth
        return f(depth - 1, verbose)

    try:
        f(4)
    except Exception:
        app = QtWidgets.QApplication(sys.argv)
        d = GSDViewExceptionDialog()
        # d = ExceptionDialog()
        d.show()
        app.exec_()
    print('done.')
Exemple #3
0
    def excepthook(self, exctype, excvalue, tracebackobj):
        '''Global function to catch unhandled exceptions.

        :param exctype:
            exception class
        :param excvalue:
            exception instance
        :param tracebackobj:
            traceback object

        '''

        sys.__excepthook__(exctype, excvalue, tracebackobj)
        # No messages for keyboard interruts
        if not issubclass(exctype, Exception):
        #~ if issubclass(exctype, KeyboardInterrupt):
            msg = str(excvalue)
            if not msg:
                msg = excvalue.__class__.__name__
            _log.info(msg)
            self.close()
            return

        # @TODO: check
        # Guard for avoiding multiple dialog opening
        if hasattr(self, '_busy'):
            return
        self._busy = True

        # @TODO: sometimes a RuntimeError is raised claiming that the
        #        "underlying C/C++ object has been deleted".
        #        Try to build the dialog without parent (self) and check
        #        modality.
        dialog = ExceptionDialog(exctype, excvalue, tracebackobj, self)
        #dialog.show()
        ret = dialog.exec_()
        if ret == QtWidgets.QDialog.Rejected:
            self.close()
        else:
            _log.warning('ignoring an unhandled exception may cause '
                         'program malfunctions.')