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 2 1968
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(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?
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(tracebac k.print_exc)
Help on function print_exc in module traceback:
print_exc(limit =None, file=None)
Shorthand for 'print_exceptio n(sys.exc_type, sys.exc_value,
sys.exc_traceba ck, 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
"Sami" <sa********@NOS PAMbtinternet.c omwrote 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 exception Error in file module.py:
$ python
Python 2.3 (#1, Sep 12 2003, 15:05:00)
on linux2
Type "help", "copyright", "credits" or "license" for more information.
|
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
|
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
after I read the documentation but I can't find any problems yet. I'm
catching all errors throughout the code into a function and I write
the traceback to the server log as well as the screen. That's all. I
need not to save it or anything else. The documentation said the
function (in this example...
|
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
object.
Now, the traceback module has print_exc and format_exc methods that are
supposed to take a traceback object and return a formatted traceback
like the default output. Unfortunately I keep getting 'None' out of
them. Not sure why.
|
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 them by reading the appropriate TraceBack from stderr.
I can put something like:
try:
self.call_handler(handler,*args)
except Exception, e:
print e
print e.args
| |
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 (between
running on Solaris, Linux, OSX and Windows systems there might not be any
command window or terminal window to show the traceback messages in). Do I
want to do something like override the print_exc (or format_exc?) method of
traceback to get the text of the message and call my dialog box...
|
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 in conjunction with
StringIO:
import StringIO, traceback
try:
raise Exception
except:
|
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 a pretty traceback just like the Python interactive
interpreter does, but only show the part of the traceback relating to
the code sent to exec.
For example here is the code I'm using:
try:
exec code
|
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* exception, not only this specific one, I presume? print_exc writes "the exception currently being handled", not the one you're creating right now. Put the code above into your exception handler:
try:
1/0
except:
f = open('filename.txt', 'a')
traceback.print_exc(file=f)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |