]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-23915: update and elucidate documentation of with_traceback (GH-23680)
authorIrit Katriel <iritkatriel@yahoo.com>
Wed, 16 Dec 2020 16:03:32 +0000 (16:03 +0000)
committerGitHub <noreply@github.com>
Wed, 16 Dec 2020 16:03:32 +0000 (17:03 +0100)
Doc/library/exceptions.rst

index 8fb25a50e2d40468280dbbd7590effabcc9b72bf..1028213699d63727db2a33a91e377d91ce797224 100644 (file)
@@ -90,8 +90,13 @@ The following exceptions are used mostly as base classes for other exceptions.
    .. method:: with_traceback(tb)
 
       This method sets *tb* as the new traceback for the exception and returns
-      the exception object.  It is usually used in exception handling code like
-      this::
+      the exception object.  It was more commonly used before the exception
+      chaining features of :pep:`3134` became available.  The following example
+      shows how we can convert an instance of ``SomeException`` into an
+      instance of ``OtherException`` while preserving the traceback.  Once
+      raised, the current frame is pushed onto the traceback of the
+      ``OtherException``, as would have happened to the traceback of the
+      original ``SomeException`` had we allowed it to propagate to the caller.
 
          try:
              ...