# cpython-withatomic / Doc / libtraceback.tex

The branch 'legacy-trunk' does not exist.
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 \section{Standard Module \sectcode{traceback}} \stmodindex{traceback} \renewcommand{\indexsubitem}{(in module 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}. The module defines the following functions: \begin{funcdesc}{print_tb}{traceback\optional{\, limit}} 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} \begin{funcdesc}{extract_tb}{traceback\optional{\, limit}} 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} \begin{funcdesc}{print_exception}{type\, value\, traceback\optional{\, limit}} Print exception information and up to \var{limit} stack trace entries from \var{traceback}. This differs from \code{print_tb} in the following ways: (1) if \var{traceback} is not \code{None}, it prints a header \code{Traceback (innermost last):}''; (2) it prints the exception \var{type} and \var{value} after the stack trace; (3) if \var{type} is \code{SyntaxError} and \var{value} has the appropriate format, it prints the line where the syntax error occurred with a caret indication the approximate position of the error. \end{funcdesc} \begin{funcdesc}{print_exc}{\optional{limit}} This is a shorthand for \code{print_exception(sys.exc_type,} \code{sys.exc_value,} \code{sys.exc_traceback,} \code{limit)}. \end{funcdesc} \begin{funcdesc}{print_last}{\optional{limit}} This is a shorthand for \code{print_exception(sys.last_type,} \code{sys.last_value,} \code{sys.last_traceback,} \code{limit)}. \end{funcdesc} 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.