cpython/Doc/libtraceback.tex

56 lines
2.4 KiB
TeX
Raw Normal View History

\section{Standard Module \sectcode{traceback}}
\label{module-traceback}
1995-03-01 10:36:00 -04:00
\stmodindex{traceback}
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.
The module uses traceback objects --- this is the object type
that is stored in the variables \code{sys.exc_traceback} and
\code{sys.last_traceback}.
1998-03-08 02:12:10 -04:00
\obindex{traceback}
1995-03-01 10:36:00 -04:00
The module defines the following functions:
1998-03-08 02:12:10 -04:00
\begin{funcdesc}{print_tb}{traceback\optional{, limit}}
1995-03-01 10:36:00 -04:00
Print up to \var{limit} stack trace entries from \var{traceback}. If
\var{limit} is omitted or \code{None}, all entries are printed.
\end{funcdesc}
1998-03-08 02:12:10 -04:00
\begin{funcdesc}{extract_tb}{traceback\optional{, limit}}
1995-03-01 10:36:00 -04:00
Return a list of up to \var{limit} ``pre-processed'' stack trace
entries extracted from \var{traceback}. It is useful for alternate
formatting of stack traces. If \var{limit} is omitted or \code{None},
all entries are extracted. A ``pre-processed'' stack trace entry is a
quadruple (\var{filename}, \var{line number}, \var{function name},
\var{line text}) representing the information that is usually printed
for a stack trace. The \var{line text} is a string with leading and
trailing whitespace stripped; if the source is not available it is
\code{None}.
\end{funcdesc}
1998-03-08 02:12:10 -04:00
\begin{funcdesc}{print_exception}{type, value, traceback\optional{, limit}}
1995-03-01 10:36:00 -04:00
Print exception information and up to \var{limit} stack trace entries
1998-03-08 02:12:10 -04:00
from \var{traceback}. This differs from \function{print_tb()} in the
1995-03-01 10:36:00 -04:00
following ways: (1) if \var{traceback} is not \code{None}, it prints a
1998-03-08 02:12:10 -04:00
header \samp{Traceback (innermost last):}; (2) it prints the
1995-03-01 10:36:00 -04:00
exception \var{type} and \var{value} after the stack trace; (3) if
1998-03-08 02:12:10 -04:00
\var{type} is \exception{SyntaxError} and \var{value} has the appropriate
1995-03-01 10:36:00 -04:00
format, it prints the line where the syntax error occurred with a
1998-03-08 02:12:10 -04:00
caret indicating the approximate position of the error.
1995-03-01 10:36:00 -04:00
\end{funcdesc}
\begin{funcdesc}{print_exc}{\optional{limit}}
1998-03-08 02:12:10 -04:00
This is a shorthand for `\code{print_exception(sys.exc_type,}
\code{sys.exc_value,} \code{sys.exc_traceback,} \var{limit}\code{)}'.
1995-03-01 10:36:00 -04:00
\end{funcdesc}
\begin{funcdesc}{print_last}{\optional{limit}}
1998-03-08 02:12:10 -04:00
This is a shorthand for `\code{print_exception(sys.last_type,}
\code{sys.last_value,} \code{sys.last_traceback,} \var{limit}\code{)}'.
1995-03-01 10:36:00 -04:00
\end{funcdesc}