home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
pyhtmldoc
/
t
/
traceback
< prev
next >
Wrap
Text File
|
1996-11-14
|
3KB
|
52 lines
<TITLE>traceback -- Python library reference</TITLE>
Next: <A HREF="../p/pickle" TYPE="Next">pickle</A>
Prev: <A HREF="../t/types" TYPE="Prev">types</A>
Up: <A HREF="../p/python_services" TYPE="Up">Python Services</A>
Top: <A HREF="../t/top" TYPE="Top">Top</A>
<H1>3.3. Standard Module <CODE>traceback</CODE></H1>
This module provides a standard interface to format and print stack
traces of Python programs. It exactly mimics the behavior of the
Python interpreter when it prints a stack trace. This is useful when
you want to print stack traces under program control, e.g. in a
``wrapper'' around the interpreter.
<P>
The module uses traceback objects --- this is the object type
that is stored in the variables <CODE>sys.exc_traceback</CODE> and
<CODE>sys.last_traceback</CODE>.
<P>
The module defines the following functions:
<P>
<DL><DT><B>print_tb</B> (<VAR>traceback</VAR>[, <VAR>limit</VAR>]) -- function of module traceback<DD>
Print up to <VAR>limit</VAR> stack trace entries from <VAR>traceback</VAR>. If
<VAR>limit</VAR> is omitted or <CODE>None</CODE>, all entries are printed.
</DL>
<DL><DT><B>extract_tb</B> (<VAR>traceback</VAR>[, <VAR>limit</VAR>]) -- function of module traceback<DD>
Return a list of up to <VAR>limit</VAR> ``pre-processed'' stack trace
entries extracted from <VAR>traceback</VAR>. It is useful for alternate
formatting of stack traces. If <VAR>limit</VAR> is omitted or <CODE>None</CODE>,
all entries are extracted. A ``pre-processed'' stack trace entry is a
quadruple (<VAR>filename</VAR>, <VAR>line number</VAR>, <VAR>function name</VAR>,
<VAR>line text</VAR>) representing the information that is usually printed
for a stack trace. The <VAR>line text</VAR> is a string with leading and
trailing whitespace stripped; if the source is not available it is
<CODE>None</CODE>.
</DL>
<DL><DT><B>print_exception</B> (<VAR>type</VAR>, <VAR>value</VAR>, <VAR>traceback</VAR>[, <VAR>limit</VAR>]) -- function of module traceback<DD>
Print exception information and up to <VAR>limit</VAR> stack trace entries
from <VAR>traceback</VAR>. This differs from <CODE>print_tb</CODE> in the
following ways: (1) if <VAR>traceback</VAR> is not <CODE>None</CODE>, it prints a
header ``<CODE>Traceback (innermost last):</CODE>''; (2) it prints the
exception <VAR>type</VAR> and <VAR>value</VAR> after the stack trace; (3) if
<VAR>type</VAR> is <CODE>SyntaxError</CODE> and <VAR>value</VAR> has the appropriate
format, it prints the line where the syntax error occurred with a
caret indication the approximate position of the error.
</DL>
<DL><DT><B>print_exc</B> ([<VAR>limit</VAR>]) -- function of module traceback<DD>
This is a shorthand for <CODE>print_exception(sys.exc_type,</CODE>
<CODE>sys.exc_value,</CODE> <CODE>sys.exc_traceback,</CODE> <CODE>limit)</CODE>.
</DL>
<DL><DT><B>print_last</B> ([<VAR>limit</VAR>]) -- function of module traceback<DD>
This is a shorthand for <CODE>print_exception(sys.last_type,</CODE>
<CODE>sys.last_value,</CODE> <CODE>sys.last_traceback,</CODE> <CODE>limit)</CODE>.
</DL>