Python 2.5b2 and excepthook problem

L

Larry Bates

I have some classes that trap hook sys.excepthook and log
exceptions prior to the program exiting. This has proven
to be an effective way to log what is going on with many
of my "lights out" processes. I'm doing some testing with
Python 2.5b2 and can't seem to get it to work properly.
Here is a very small script that I think should work but
doesn't.

import sys

def excepthook(type, value, tb):
import traceback
print "entering my excepthook function"
tblines=traceback.format_exception(type, value, tb)
#traceback.print_tb(tb)
return

if __name__=="__main__":
sys.excepthook=excepthook
print "sys.excepthook=", sys.excepthook
a=[1,2,3]
b=a[4]

When I run this I get:

sys.excepthook= <function excepthook at 0x0140E070>
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "K:\SYSCON\PYTHON\ZBKUP\junk.py", line 14, in <module>
b=a[4]
IndexError: list index out of range
The sys.excepthook is clearly pointing to my function, but when
the exception occurs the function isn't called because the print
statement isn't executed upon entering the function. Has something
changed that I missed?

Thanks in advance for any assistance.

Regards,
Larry Bates
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top