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 1969
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |