Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How can I print a traceback without raising an exception?

Reply
Thread Tools

How can I print a traceback without raising an exception?

 
 
Gerald Britton
Guest
Posts: n/a
 
      02-13-2011
In the following example, I raise an exception in function h() which
prints a traceback. I would like to know how I can get a similar
display on my terminal without raising an exception. That is, can I
replace "raise Exception" in function h() with some sequence of
instructions (possibly using the inspect module) that will generate a
similar call trace of how I got to that point?

Example:

>>> def f():

.... g()
....
>>> def g():

.... h()
....
>>> def h():

.... raise Exception # Replace with something to generate a call trace
....
>>> f()

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in f
File "<stdin>", line 2, in g
File "<stdin>", line 2, in h
Exception
>>>



--
Gerald Britton
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
"raise (type, value, traceback)" and "raise type, value, traceback" Jack Bates Python 0 05-02-2011 05:23 PM
how to print a traceback? sndive@gmail.com Python 1 10-16-2007 08:34 AM
How can i print from the broweser without displaying the dialog print ? Tamer Ibrahim ASP .Net 3 01-29-2007 10:52 AM
howto catch an Exception and still print the TraceBack? Saizan Python 5 02-02-2006 09:53 AM



Advertisments