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(et ype, value, tb):
print "in Myexcepthook\n"
import traceback
lines=traceback .format_excepti on(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\Progra mming\Python\Tr yProjects\Excep tHandling1\Exce pt2.py", lin
15, in <module>
x = 1/0
ZeroDivisionErr or: integer division or modulo by zero
None
--------------------------------------------------------------------------
I never see the value 78.
What am I doing wrong?
Thanks,
Sami
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(et ype, value, tb):
print "in Myexcepthook\n"
import traceback
lines=traceback .format_excepti on(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\Progra mming\Python\Tr yProjects\Excep tHandling1\Exce pt2.py", lin
15, in <module>
x = 1/0
ZeroDivisionErr or: integer division or modulo by zero
None
--------------------------------------------------------------------------
I never see the value 78.
What am I doing wrong?
Thanks,
Sami
Comment