mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-23915: update and elucidate documentation of with_traceback (GH-23680)
This commit is contained in:
parent
fc3dca3e16
commit
c590c2338e
1 changed files with 7 additions and 2 deletions
|
@ -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:
|
||||
...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue