Sami Islam wrote: > > I am new to Python. > > This is my code: > ------------------------------------------- > import sys > import traceback > > def MyExHook(typ, val, tb): > print "Inside MyExHook" > tb.print_exception(typ, val, tb) > > T, V, B = sys.exc_info() > sys.excepthook = MyExHook(T, V, B) > > x = 1/0 > ------------------------------------------- > and this is what I get > ------------------------------------------ > Inside MyExHook > > Traceback (most recent call last): > File > "E:/Home/Programming/Python/TryProjects/ExceptHandling1/Except4.py", > line 11, in > sys.excepthook = MyExHook(T, V, B) > File > "E:/Home/Programming/Python/TryProjects/ExceptHandling1/Except4.py", > line 6, in MyExHook > tb.print_exception(typ, val, tb) > AttributeError: print_exception > -------------------------------------------------------------------------------------------------------- > > I can see that my MyExHook is being called (it wasn't being called when > I had previously set sys.excepthook = MyExHook without parameters). The > parameters to print_exception are what they should be.
No, they aren't. Did you try adding print typ, val, tb in MyExHook? In my Python 2.4 environment, it prints "None None None", because that's what sys.exc_info returns when there has not been an exception. > What am I doing wrong? sys.excepthook needs to be set to a function. You are calling MyExHook with three garbage parameters, and then passing its result (which is None in this case) to sys.excepthook. MyExHook is not being called when the exception happens, because the exception hook is set to None. The right way to do this is: sys.excepthook = MyExHook x = 1/0 I just tried that, and it worked fine. If that's not working for you, tell us what you do get. -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32