summaryrefslogtreecommitdiffstats
path: root/Doc/library/exceptions.rst
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-02-26 07:49:52 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-02-26 07:49:52 (GMT)
commitab7bf2143e67ddc1510413fa0d7f9c621adf22fa (patch)
tree62a24ed4f57e4db638ebde745bb83e2e09fc86e3 /Doc/library/exceptions.rst
parentcda6b6d60d96e6f755da92deb5e4066839095791 (diff)
downloadcpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.zip
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.gz
cpython-ab7bf2143e67ddc1510413fa0d7f9c621adf22fa.tar.bz2
Close issue #6210: Implement PEP 409
Diffstat (limited to 'Doc/library/exceptions.rst')
-rw-r--r--Doc/library/exceptions.rst18
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index 3f1a30d..7e3a0c3 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -34,6 +34,24 @@ programmers are encouraged to at least derive new exceptions from the
defining exceptions is available in the Python Tutorial under
:ref:`tut-userexceptions`.
+When raising (or re-raising) an exception in an :keyword:`except` clause
+:attr:`__context__` is automatically set to the last exception caught; if the
+new exception is not handled the traceback that is eventually displayed will
+include the originating exception(s) and the final exception.
+
+This implicit exception chain can be made explicit by using :keyword:`from`
+with :keyword:`raise`. The single argument to :keyword:`from` must be an
+exception or :const:`None`, and it will bet set as :attr:`__cause__` on the
+raised exception. If :attr:`__cause__` is an exception it will be displayed
+instead of :attr:`__context__`; if :attr:`__cause__` is None,
+:attr:`__context__` will not be displayed by the default exception handling
+code. (Note: the default value for :attr:`__context__` is :const:`None`,
+while the default value for :attr:`__cause__` is :const:`Ellipsis`.)
+
+In either case, the default exception handling code will not display
+any of the remaining links in the :attr:`__context__` chain if
+:attr:`__cause__` has been set.
+
Base classes
------------