Browse files

Improve exception diagnostics

  • Loading branch information...
1 parent a60e402 commit 29e5a20520816e0170bfa293d1dcdc352a5cd177 @batterseapower batterseapower committed Dec 6, 2009
Showing with 12 additions and 3 deletions.
  1. +3 −1 pinyin/forms/
  2. +9 −2 pinyin/
@@ -50,10 +50,12 @@ def __init__(self, view, notifier, dbbuilder, compulsory):
# Create and run a thread that just constructs the database
class Worker(QThread):
def run(self):
+ # NB: do not use suppressexceptions because throwing an exception at this point
+ # can cause segfaults in PyQt4 -- we better suppress the exception for developers too!
- except Exception, e:
+ except:
log.exception("Suppressed exception in database build process")
self.emit(SIGNAL("buildfailure(PyQt_PyObject)"), sys.exc_info())
@@ -36,13 +36,16 @@ def suppressexceptions(action):
if debugmode():
# Don't suppress exceptions for the developers!
+ return True
+ return True
# NB: have to delay the import of logger because it depends on utils
from logger import log
log.exception("Had to suppress an exception")
+ return False
Utility function that reports whether a string consists only of punctuation character
@@ -181,18 +184,22 @@ def __init__(self, function):
self.__called = False
self.__result = None
self.__function = function
+ # For error messages only:
+ import traceback
+ self.__thunk_stack = traceback.format_stack()
def __call__(self):
if self.__called:
return self.__result
elif self.__called is None:
- raise ValueError("A thunked computation entered a black hole")
+ raise ValueError("A thunked computation entered a black hole! Created at:\n" + "".join(self.__thunk_stack))
self.__called = None # Indicates that this thunk has become a black hole
self.__result = self.__function()
self.__called = True
- except Exception, e:
+ except:
from pinyin.logger import log
# Thunked actions raising an exception is a massively bad idea, because there
# is no way to know whose exception handler will be on the stack at the time we

0 comments on commit 29e5a20

Please sign in to comment.