def exception_hook(self, exctype, excvalue, tb): """Handle uncaught python exceptions. It'll try very hard to write all open tabs to a file, and then exit gracefully. """ exc = (exctype, excvalue, tb) if not self._quitter.quit_status['crash']: log.misc.error("ARGH, there was an exception while the crash " "dialog is already shown:", exc_info=exc) return log.misc.error("Uncaught exception", exc_info=exc) is_ignored_exception = (exctype is bdb.BdbQuit or not issubclass(exctype, Exception)) if 'pdb-postmortem' in self._args.debug_flags: pdb.post_mortem(tb) if is_ignored_exception or 'pdb-postmortem' in self._args.debug_flags: # pdb exit, KeyboardInterrupt, ... sys.exit(usertypes.Exit.exception) self._quitter.quit_status['crash'] = False info = self._get_exception_info() try: ipc.server.ignored = True except Exception: log.destroy.exception("Error while ignoring ipc") try: self._app.lastWindowClosed.disconnect( self._quitter.on_last_window_closed) except TypeError: log.destroy.exception("Error while preventing shutdown") global is_crashing is_crashing = True self._app.closeAllWindows() if self._args.no_err_windows: crashdialog.dump_exception_info(exc, info.pages, info.cmd_history, info.objects) else: self._crash_dialog = crashdialog.ExceptionCrashDialog( self._args.debug, info.pages, info.cmd_history, exc, info.objects) ret = self._crash_dialog.exec_() if ret == crashdialog.Result.restore: self._quitter.restart(info.pages) # We might risk a segfault here, but that's better than continuing to # run in some undefined state, so we only do the most needed shutdown # here. qInstallMessageHandler(None) self.destroy_crashlogfile() sys.exit(usertypes.Exit.exception)
def exception_hook(self, exctype, excvalue, tb): """Handle uncaught python exceptions. It'll try very hard to write all open tabs to a file, and then exit gracefully. """ exc = (exctype, excvalue, tb) if self._handle_early_exits(exc): return self._quitter.quit_status['crash'] = False info = self._get_exception_info() if ipc.server is not None: try: ipc.server.ignored = True except Exception: log.destroy.exception("Error while ignoring ipc") try: self._app.lastWindowClosed.disconnect( self._quitter.on_last_window_closed) except TypeError: log.destroy.exception("Error while preventing shutdown") self.is_crashing = True self._app.closeAllWindows() if self._args.no_err_windows: crashdialog.dump_exception_info(exc, info.pages, info.cmd_history, info.objects) else: self._crash_dialog = crashdialog.ExceptionCrashDialog( self._args.debug, info.pages, info.cmd_history, exc, info.objects) ret = self._crash_dialog.exec() if ret == crashdialog.Result.restore: self._quitter.restart(info.pages) # We might risk a segfault here, but that's better than continuing to # run in some undefined state, so we only do the most needed shutdown # here. qInstallMessageHandler(None) self.destroy_crashlogfile() sys.exit(usertypes.Exit.exception)
def _exception_hook(self, exctype, excvalue, tb): # noqa """Handle uncaught python exceptions. It'll try very hard to write all open tabs to a file, and then exit gracefully. """ # pylint: disable=broad-except exc = (exctype, excvalue, tb) if not self._quit_status['crash']: log.misc.error( "ARGH, there was an exception while the crash " "dialog is already shown:", exc_info=exc) return log.misc.error("Uncaught exception", exc_info=exc) is_ignored_exception = (exctype is bdb.BdbQuit or not issubclass(exctype, Exception)) if is_ignored_exception or self._args.no_crash_dialog: # pdb exit, KeyboardInterrupt, ... status = 0 if is_ignored_exception else 2 try: self.shutdown(status) return except Exception: log.init.exception("Error while shutting down") self.quit() return self._quit_status['crash'] = False try: pages = self._recover_pages(forgiving=True) except Exception: log.destroy.exception("Error while recovering pages") pages = [] try: history = objreg.get('command-history')[-5:] except Exception: log.destroy.exception("Error while getting history: {}") history = [] try: objects = self.get_all_objects() except Exception: log.destroy.exception("Error while getting objects") objects = "" try: objreg.get('ipc-server').ignored = True except Exception: log.destroy.exception("Error while ignoring ipc") try: self.lastWindowClosed.disconnect(self.shutdown) except TypeError: log.destroy.exception("Error while preventing shutdown") QApplication.closeAllWindows() self._crashdlg = crashdialog.ExceptionCrashDialog( self._args.debug, pages, history, exc, objects) ret = self._crashdlg.exec_() if ret == QDialog.Accepted: # restore self.restart(shutdown=False, pages=pages) # We might risk a segfault here, but that's better than continuing to # run in some undefined state, so we only do the most needed shutdown # here. qInstallMessageHandler(None) self._destroy_crashlogfile() sys.exit(1)