472,328 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

traceback.print_exc() supposed to stop exception propagation.

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\ExceptHand ling1\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
Apr 6 '08 #1
2 1887
Sami schrieb:
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\ExceptHand ling1\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?
Trusting a wrong source. Or misinterpreting it.

Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
imWelcome to rlcompleter2 0.96
for nice experiences hit <tabmultiple times
>>import traceback
help(traceback.print_exc)
Help on function print_exc in module traceback:

print_exc(limit=None, file=None)
Shorthand for 'print_exception(sys.exc_type, sys.exc_value,
sys.exc_traceback, limit, file)'.
(In fact, it uses sys.exc_info() to retrieve the same information
in a thread-safe way.)
>>>
Nothing in there says that this would prevent the exception from being
propagated.

Diez
Apr 6 '08 #2

"Sami" <sa********@NOSPAMbtinternet.comwrote in message
news:69******************************@bt.com...
| 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.

It is possible that the unspecified book describes an unspecified Python
version that is not the same as the unspecified version that you tested
with ;-).

Help respondants by providing version info. Sometimes even the system/OS
info is helpful, though probably not relevant here.

tjr

Apr 6 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jan Decaluwe | last post by:
Hi: There is a difference between exception info formatting by the interpreter versus the traceback module. For example, say we define an...
1
by: fowlertrainer | last post by:
Hello python-list, This is a thread's run method. def run(self): try: page=urllib.urlopen(base) src=page.read() page=None self.ResultCode=0
0
by: Ehab Teima | last post by:
Hello, I have built a server application. It's multithreaded, and everything works fine so far. I have only one issue with catching exceptions...
1
by: Michael P. Soulier | last post by:
Hello, For a GUI app I've tried resetting sys.excepthook to my own exceptionhandler bound method, which accepts a type, value and traceback...
5
by: Saizan | last post by:
In an event-driven application i'd like to keep the program alive regardless of any exceptions raised by the handlers, but still be able to debug...
5
by: Bob Greschke | last post by:
I want to cause any traceback output from my applications to show up in one of my dialog boxes, instead of in the command or terminal window...
4
by: billiejoex | last post by:
Hi there, I'm facing a case where I need to get the traceback outptut when occurring an exception. I solved such problem by using traceback module...
8
by: gregpinero | last post by:
I'm running code via the "exec in context" statement within a much larger program. What I would like to do is capture any possible errors and show...
0
by: Gabriel Genellina | last post by:
En Mon, 26 May 2008 05:31:27 -0300, <Dominique.Holzwarth@ch.delarue.comescribió: Don't inherit from Exception - you should be able to log *any*...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.