def _excepthook(self, etype, value, tb): if isinstance(etype, ChildProcessException): s = "Using GUI:\n\n" + value.printable_traceback else: s = "Using GUI:\n\n" + get_str_from_traceback(etype, value, tb) # bug - display a dialog with the entire exception and traceback printed out traceback.print_tb(tb) dlg = wx.MessageDialog(self.main_window, ERROR_MSG + "\n" + QUESTION_TEXT, style=wx.ICON_ERROR | wx.YES_NO) # Get a string with the traceback and send it answer = dlg.ShowModal() if answer == wx.ID_YES: print "Sending bug report!" bugsender = BugReporter(error_str=s) success = bugsender.send() # Dialog with success or not of the ftp uploading if success: msg = "The bug report was successfully uploaded." style = 0 else: msg = "Couldn't upload the bug report!\n\nPlease, try again later." style = wx.ICON_ERROR dlg = wx.MessageDialog(self.main_window, msg, style=style) dlg.ShowModal() else: dlg = wx.MessageDialog(self.main_window, "Error msg:\n\n" + s, style=wx.ICON_ERROR) dlg.ShowModal()
if __name__ == '__main__': ERROR_MSG = "\n\nOps! Something went really wrong and regionfixer crashed. I can try to send an automatic bug rerpot if you wish.\n\n" QUESTION_TEXT = ('Do you want to send an anonymous bug report to the region fixer ftp?\n' '(Answering no will print the bug report)') had_exception = False auto_reported = False try: freeze_support() value = main() sys.exit(value) except ChildProcessException as e: had_exception = True print(ERROR_MSG) bug_sender = BugReporter(e.printable_traceback) auto_reported = bug_sender.ask_and_send(QUESTION_TEXT) bug_report = bug_sender.error_str except Exception as e: had_exception = True print(ERROR_MSG) # Traceback will be taken in init bug_sender = BugReporter() auto_reported = bug_sender.ask_and_send(QUESTION_TEXT) bug_report = bug_sender.error_str finally: if had_exception and not auto_reported: print("") print("Bug report:")
auto_reported = False value = 0 try: freeze_support() value = main() except SystemExit as e: # sys.exit() was called within the program had_exception = False value = e.code except ChildProcessException as e: had_exception = True print(ERROR_MSG) bug_sender = BugReporter(e.printable_traceback) # auto_reported = bug_sender.ask_and_send(QUESTION_TEXT) bug_report = bug_sender.error_str value = c.RV_CRASH except Exception as e: had_exception = True print(ERROR_MSG) # Traceback will be taken in init bug_sender = BugReporter() # auto_reported = bug_sender.ask_and_send(QUESTION_TEXT) bug_report = bug_sender.error_str value = c.RV_CRASH finally: if had_exception and not auto_reported:
ERROR_MSG = "\n\nOps! Something went really wrong and regionfixer crashed. I can try to send an automatic bug rerpot if you wish.\n\n" QUESTION_TEXT = ( 'Do you want to send an anonymous bug report to the region fixer ftp?\n' '(Answering no will print the bug report)') had_exception = False auto_reported = False try: freeze_support() value = main() sys.exit(value) except ChildProcessException as e: had_exception = True print(ERROR_MSG) bug_sender = BugReporter(e.printable_traceback) auto_reported = bug_sender.ask_and_send(QUESTION_TEXT) bug_report = bug_sender.error_str except Exception as e: had_exception = True print(ERROR_MSG) # Traceback will be taken in init bug_sender = BugReporter() auto_reported = bug_sender.ask_and_send(QUESTION_TEXT) bug_report = bug_sender.error_str finally: if had_exception and not auto_reported: print("") print("Bug report:")