I decided I wanted to implement an email function so that when an
unhandled exception occurs, it is emailed to myself. I've got this
working however, I want to re-raise the exception so the user knows that
an exception occurred.
I've got my except hook like below:
def MyExceptHook(type_, value, tb):
...code that does the emailing...
#Reraise the exception so the user knows that an error occured
raise type_
sys.excepthook = MyExceptHook
Now, the exception does get raised, but the traceback looks a little
funny. My app already redirects stdout/stderr to a TextCtrl and here's
what I get:
Error in sys.excepthook:
Traceback (most recent call last):
File "D:\Documents and
Settings\rickkylw\Desktop\Scripts\WellExplorer\WellExplorer.pyw", line
11923, in MyExceptHook
raise type_
NameError
Original exception was:
Traceback (most recent call last):
File "D:\Documents and
Settings\rickkylw\Desktop\Scripts\WellExplorer\WellExplorer.pyw", line
5268, in OnBugReport
frame = BugReportDialog(self, "Submit a Bug Report")
File "D:\Documents and
Settings\rickkylw\Desktop\Scripts\WellExplorer\WellExplorer.pyw", line
2368, in __init__
print x
NameError: global name 'x' is not defined
But, the email that I get has this:
Traceback (most recent call last):
File "D:\Documents and
Settings\rickkylw\Desktop\Scripts\WellExplorer\WellExplorer.pyw", line
5268, in OnBugReport
frame = BugReportDialog(self, "Submit a Bug Report")
File "D:\Documents and
Settings\rickkylw\Desktop\Scripts\WellExplorer\WellExplorer.pyw", line
2368, in __init__
print x
NameError: global name 'x' is not defined
I intentionally put a statement I knew would raise an exception "print
x" in my class. Is there a way to raise the last exception such that it
looks like the text from the emailed version?
I know this is slightly OT, but I figured some of you gurus would know
-Kyle Rickey