traceback.print_exc() supposed to stop exception propagation.

Sami sami.islam at NOSPAMbtinternet.com
Sun Apr 6 15:16:46 EDT 2008


Hello,

In the Python book that I am using to learn the language it says that 
the traceback.print_exc() can be used to stop exception propagation and 
make the program keep running.

Here is a simple piece of code that I typed in to test this fact:
---------------------------------------------------------------------------
import sys

def Myexcepthook(etype, value, tb):
     print "in Myexcepthook\n"
     import traceback
     lines=traceback.format_exception(etype, value, tb)
     print "\n".join(lines)
     traceback.print_exc()


sys.excepthook = Myexcepthook

x = 1/0

x = 78

print x
--------------------------------------------------------------------------
The Output:
--------------------------------------------------------------------------
in Myexcepthook

Traceback (most recent call last):

   File 
"E:\Home\Programming\Python\TryProjects\ExceptHandling1\Except2.py", lin
  15, in <module>
     x = 1/0

ZeroDivisionError: integer division or modulo by zero

None
--------------------------------------------------------------------------

I never see the value 78.

What am I doing wrong?

Thanks,
Sami



More information about the Python-list mailing list