traceback doc update

This commit is contained in:
Will McGugan 2021-08-03 17:27:42 +01:00
parent 774c7c224d
commit c41b654d75
1 changed files with 13 additions and 5 deletions

View File

@ -1,7 +1,11 @@
Traceback
=========
Rich can render Python tracebacks with syntax highlighting and formatting. Rich tracebacks are easier to read, and show more code, than standard Python tracebacks.
Rich can render Python tracebacks with syntax highlighting and formatting. Rich tracebacks are easier to read and show more code than standard Python tracebacks.
To see an example of a Rich traceback, running the following command::
python -m rich.traceback
Printing tracebacks
@ -9,14 +13,18 @@ Printing tracebacks
The :meth:`~rich.console.Console.print_exception` method will print a traceback for the current exception being handled. Here's an example::
import rich
from rich.console import Console
console = Console()
try:
do_something()
except:
console = rich.console.Console()
except Exception:
console.print_exception(show_locals=True)
The ``show_locals=True`` parameter causes Rich to display the value of local variables for each section of the traceback.
The ``show_locals=True`` parameter causes Rich to display the value of local variables for each frame of the traceback.
See `exception.py <https://github.com/willmcgugan/rich/blob/master/examples/exception.py>`_ for a larger example.
Traceback handler
-----------------