Skip to content

Commit c590c23

Browse files
authored
bpo-23915: update and elucidate documentation of with_traceback (GH-23680)
1 parent fc3dca3 commit c590c23

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Doc/library/exceptions.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ The following exceptions are used mostly as base classes for other exceptions.
9090
.. method:: with_traceback(tb)
9191

9292
This method sets *tb* as the new traceback for the exception and returns
93-
the exception object. It is usually used in exception handling code like
94-
this::
93+
the exception object. It was more commonly used before the exception
94+
chaining features of :pep:`3134` became available. The following example
95+
shows how we can convert an instance of ``SomeException`` into an
96+
instance of ``OtherException`` while preserving the traceback. Once
97+
raised, the current frame is pushed onto the traceback of the
98+
``OtherException``, as would have happened to the traceback of the
99+
original ``SomeException`` had we allowed it to propagate to the caller.
95100

96101
try:
97102
...

0 commit comments

Comments
 (0)