home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / t / traceback < prev    next >
Text File  |  1996-11-14  |  3KB  |  52 lines

  1. <TITLE>traceback -- Python library reference</TITLE>
  2. Next: <A HREF="../p/pickle" TYPE="Next">pickle</A>  
  3. Prev: <A HREF="../t/types" TYPE="Prev">types</A>  
  4. Up: <A HREF="../p/python_services" TYPE="Up">Python Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>3.3. Standard Module <CODE>traceback</CODE></H1>
  7. This module provides a standard interface to format and print stack
  8. traces of Python programs.  It exactly mimics the behavior of the
  9. Python interpreter when it prints a stack trace.  This is useful when
  10. you want to print stack traces under program control, e.g. in a
  11. ``wrapper'' around the interpreter.
  12. <P>
  13. The module uses traceback objects --- this is the object type
  14. that is stored in the variables <CODE>sys.exc_traceback</CODE> and
  15. <CODE>sys.last_traceback</CODE>.
  16. <P>
  17. The module defines the following functions:
  18. <P>
  19. <DL><DT><B>print_tb</B> (<VAR>traceback</VAR>[, <VAR>limit</VAR>]) -- function of module traceback<DD>
  20. Print up to <VAR>limit</VAR> stack trace entries from <VAR>traceback</VAR>.  If
  21. <VAR>limit</VAR> is omitted or <CODE>None</CODE>, all entries are printed.
  22. </DL>
  23. <DL><DT><B>extract_tb</B> (<VAR>traceback</VAR>[, <VAR>limit</VAR>]) -- function of module traceback<DD>
  24. Return a list of up to <VAR>limit</VAR> ``pre-processed'' stack trace
  25. entries extracted from <VAR>traceback</VAR>.  It is useful for alternate
  26. formatting of stack traces.  If <VAR>limit</VAR> is omitted or <CODE>None</CODE>,
  27. all entries are extracted.  A ``pre-processed'' stack trace entry is a
  28. quadruple (<VAR>filename</VAR>, <VAR>line number</VAR>, <VAR>function name</VAR>,
  29. <VAR>line text</VAR>) representing the information that is usually printed
  30. for a stack trace.  The <VAR>line text</VAR> is a string with leading and
  31. trailing whitespace stripped; if the source is not available it is
  32. <CODE>None</CODE>.
  33. </DL>
  34. <DL><DT><B>print_exception</B> (<VAR>type</VAR>, <VAR>value</VAR>, <VAR>traceback</VAR>[, <VAR>limit</VAR>]) -- function of module traceback<DD>
  35. Print exception information and up to <VAR>limit</VAR> stack trace entries
  36. from <VAR>traceback</VAR>.  This differs from <CODE>print_tb</CODE> in the
  37. following ways: (1) if <VAR>traceback</VAR> is not <CODE>None</CODE>, it prints a
  38. header ``<CODE>Traceback (innermost last):</CODE>''; (2) it prints the
  39. exception <VAR>type</VAR> and <VAR>value</VAR> after the stack trace; (3) if
  40. <VAR>type</VAR> is <CODE>SyntaxError</CODE> and <VAR>value</VAR> has the appropriate
  41. format, it prints the line where the syntax error occurred with a
  42. caret indication the approximate position of the error.
  43. </DL>
  44. <DL><DT><B>print_exc</B> ([<VAR>limit</VAR>]) -- function of module traceback<DD>
  45. This is a shorthand for <CODE>print_exception(sys.exc_type,</CODE>
  46. <CODE>sys.exc_value,</CODE> <CODE>sys.exc_traceback,</CODE> <CODE>limit)</CODE>.
  47. </DL>
  48. <DL><DT><B>print_last</B> ([<VAR>limit</VAR>]) -- function of module traceback<DD>
  49. This is a shorthand for <CODE>print_exception(sys.last_type,</CODE>
  50. <CODE>sys.last_value,</CODE> <CODE>sys.last_traceback,</CODE> <CODE>limit)</CODE>.
  51. </DL>
  52.