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