Skip to content

Commit

Permalink
Improved example code for trackback
Browse files Browse the repository at this point in the history
- Show how to create a `console` object
- Demonstrate the `show_locals=True` parameter

Refs Textualize#1380
  • Loading branch information
simonw authored Aug 3, 2021
1 parent 6169848 commit 121d727
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/source/traceback.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ 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
try:
do_something()
except:
console.print_exception()
console = rich.console.Console()
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.

Traceback handler
-----------------

Rich can be installed as the default traceback handler so that all uncaught exceptions will be rendered with highlighting. Here's how::

from rich.traceback import install
install()
install(show_locals=True)

There are a few options to configure the traceback handler, see :func:`~rich.traceback.install` for details.
There are a few options to configure the traceback handler, see :func:`~rich.traceback.install` for details.

0 comments on commit 121d727

Please sign in to comment.