blob: ca9c374859e99658259411ae51b92570047fe161 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Standard Module \sectcode{traceback}}
Guido van Rossum81b30601995-03-01 14:36:00 +00002\stmodindex{traceback}
3
4\renewcommand{\indexsubitem}{(in module traceback)}
5
6This module provides a standard interface to format and print stack
7traces of Python programs. It exactly mimics the behavior of the
8Python interpreter when it prints a stack trace. This is useful when
9you want to print stack traces under program control, e.g. in a
10``wrapper'' around the interpreter.
11
12The module uses traceback objects --- this is the object type
13that is stored in the variables \code{sys.exc_traceback} and
14\code{sys.last_traceback}.
15
16The module defines the following functions:
17
18\begin{funcdesc}{print_tb}{traceback\optional{\, limit}}
19Print up to \var{limit} stack trace entries from \var{traceback}. If
20\var{limit} is omitted or \code{None}, all entries are printed.
21\end{funcdesc}
22
23\begin{funcdesc}{extract_tb}{traceback\optional{\, limit}}
24Return a list of up to \var{limit} ``pre-processed'' stack trace
25entries extracted from \var{traceback}. It is useful for alternate
26formatting of stack traces. If \var{limit} is omitted or \code{None},
27all entries are extracted. A ``pre-processed'' stack trace entry is a
28quadruple (\var{filename}, \var{line number}, \var{function name},
29\var{line text}) representing the information that is usually printed
30for a stack trace. The \var{line text} is a string with leading and
31trailing whitespace stripped; if the source is not available it is
32\code{None}.
33\end{funcdesc}
34
35\begin{funcdesc}{print_exception}{type\, value\, traceback\optional{\, limit}}
36Print exception information and up to \var{limit} stack trace entries
37from \var{traceback}. This differs from \code{print_tb} in the
38following ways: (1) if \var{traceback} is not \code{None}, it prints a
39header ``\code{Traceback (innermost last):}''; (2) it prints the
40exception \var{type} and \var{value} after the stack trace; (3) if
41\var{type} is \code{SyntaxError} and \var{value} has the appropriate
42format, it prints the line where the syntax error occurred with a
43caret indication the approximate position of the error.
44\end{funcdesc}
45
46\begin{funcdesc}{print_exc}{\optional{limit}}
47This is a shorthand for \code{print_exception(sys.exc_type,}
48\code{sys.exc_value,} \code{sys.exc_traceback,} \code{limit)}.
49\end{funcdesc}
50
51\begin{funcdesc}{print_last}{\optional{limit}}
52This is a shorthand for \code{print_exception(sys.last_type,}
53\code{sys.last_value,} \code{sys.last_traceback,} \code{limit)}.
54\end{funcdesc}