Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nested exceptions must be instances
  • Loading branch information
iritkatriel committed Dec 19, 2021
commit 6a99f8c76b0efb5e45a9efec3470037440a2f86e
23 changes: 20 additions & 3 deletions Doc/tutorial/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,9 @@ tasks may have failed in parallel, but there are also other use cases where
it is desirable to continue execution and collect multiple errors rather than
raise the first exception.

The builtin :exc:`ExceptionGroup` wraps a list of exceptions so that they can
be raised together. It is an exception itself, so it can be caught like any
other exception. ::
The builtin :exc:`ExceptionGroup` wraps a list of exception instances so
that they can be raised together. It is an exception itself, so it can be
caught like any other exception. ::

>>> def f():
... excs = [OSError('error 1'), SystemError('error 2')]
Comment thread
iritkatriel marked this conversation as resolved.
Expand Down Expand Up @@ -569,6 +569,23 @@ other clauses and eventually to be reraised. ::
+------------------------------------
>>>

Note that the exceptions nested in an exception group must be instances,
not types. This is because in practice the exceptions would typically
be ones that have already been raised and caught by the program, along
the following pattern::

>>> excs = []
... for test in tests:
... try:
... test.run()
... except Exception as e:
... excs.append(e)
...
... if excs:
Comment thread
iritkatriel marked this conversation as resolved.
Outdated
... raise ExceptionGroup("Test Failures", excs)
...


Enriching Exceptions with Notes
===============================

Expand Down