Changes

Jump to navigation Jump to search
Line 16: Line 16:  
===Method and Implementations===
 
===Method and Implementations===
 
Whenever any uncaught exception is raised, the interpreter calls the sys.excepthook(type,value,traceback). After some discussions at #python, we learnt how this functionality could be used in this scenario and prepared a git diff of the file src/jarabe/journal/journalactivity.py
 
Whenever any uncaught exception is raised, the interpreter calls the sys.excepthook(type,value,traceback). After some discussions at #python, we learnt how this functionality could be used in this scenario and prepared a git diff of the file src/jarabe/journal/journalactivity.py
The following is the git diff. Please find the explanations as comments
  −
diff --git a/journalactivity.py b/journalactivity.py
  −
index 44cc018..36a2e2e 100644
  −
--- a/journalactivity.py
  −
+++ b/journalactivity.py
  −
@@ -358,8 +358,20 @@ class JournalActivity(Window):
  −
        self.show_main_view()
  −
        self.search_grab_focus()
     −
''' Defining an Error Alert function in the Journal Activity Class which displays the message as
+
===Code===
   −
Operation could not be performed
+
The following is the git diff. Please find the explanations as comments -
Please check the logviewer activity for details
  −
and an OK button
  −
'''
     −
+
http://pastebin.com/7mEnHVVN
+    def uncaught_exception_alert(self):
  −
+        alert = ErrorAlert(title="Operation could not be performed", msg="Please check the logviewer activity for details ")
  −
+    alert.connect('response', self.__alert_response_cb)
  −
+    self.add_alert(alert)
  −
+    alert.show()
  −
+
  −
_journal = None
  −
  −
'''
  −
Defining a function which logs the unhandled exception as well as calls the Error Alert in the Journal whenever any uncaught exception occurs
  −
'''
     −
+def _alert_excepthook(exc_type, exc_value, traceback):
  −
+    logging.exception('Unhandled Python exception: %s', repr((exc_type, exc_value, traceback)))
  −
+    _journal.uncaught_exception_alert() 
  −
+
  −
'''
  −
When an exception is raised and uncaught, sys.excepthook is called with three arguments, the exception class, exception instance, and a traceback object.The function _alert_excepthook is called only when an unhandled exception occurs.
  −
'''
  −
  −
+sys.excepthook = _alert_excepthook
  −
+
  −
def get_journal():
  −
    global _journal
  −
    if _journal is None:
  −
  −
   
However, the above code caught the unhandled exceptions for only journal files  and displayed an error alert in the journal except for journalactivity.py. I realized that whenever any unhandled exception occurs in the file the ‘Journal’ icon itself disappears and there is no other way to go the Journal.
 
However, the above code caught the unhandled exceptions for only journal files  and displayed an error alert in the journal except for journalactivity.py. I realized that whenever any unhandled exception occurs in the file the ‘Journal’ icon itself disappears and there is no other way to go the Journal.
      
===Feedback===
 
===Feedback===

Navigation menu