@@ -585,65 +585,3 @@ the following pattern::
585585 ... raise ExceptionGroup("Test Failures", excs)
586586 ...
587587
588-
589- Enriching Exceptions with Notes
590- ===============================
591-
592- When an exception is created in order to be raised, it is usually initialized
593- with information that describes the error that has occurred. There are cases
594- where it is useful to add information after the exception was caught. For this
595- purpose, exceptions have a mutable field ``__note__ `` that can be string or
596- ``None `` (``None `` by default). If it is a string, it is included in the
597- formatted tracebacks after the exception. ::
598-
599- >>> try:
600- ... raise TypeError('bad type')
601- ... except Exception as e:
602- ... e.__note__ = 'Add some information'
603- ... raise
604- ...
605- Traceback (most recent call last):
606- File "<stdin>", line 2, in <module>
607- TypeError: bad type
608- Add some information
609- >>>
610-
611- For example, when collecting exceptions into an exception group, we may want
612- to add context information for the individual errors. In the following each
613- exception in the group has a note indicating when this error has occurred. ::
614-
615- >>> def f():
616- ... raise OSError('operation failed')
617- ...
618- >>> excs = []
619- >>> for i in range(3):
620- ... try:
621- ... f()
622- ... except Exception as e:
623- ... e.__note__ = f'Happened in Iteration {i+1}'
624- ... excs.append(e)
625- ...
626- >>> raise ExceptionGroup('We have some problems', excs)
627- + Exception Group Traceback (most recent call last):
628- | File "<stdin>", line 1, in <module>
629- | ExceptionGroup: We have some problems
630- +-+---------------- 1 ----------------
631- | Traceback (most recent call last):
632- | File "<stdin>", line 3, in <module>
633- | File "<stdin>", line 2, in f
634- | OSError: operation failed
635- | Happened in Iteration 1
636- +---------------- 2 ----------------
637- | Traceback (most recent call last):
638- | File "<stdin>", line 3, in <module>
639- | File "<stdin>", line 2, in f
640- | OSError: operation failed
641- | Happened in Iteration 2
642- +---------------- 3 ----------------
643- | Traceback (most recent call last):
644- | File "<stdin>", line 3, in <module>
645- | File "<stdin>", line 2, in f
646- | OSError: operation failed
647- | Happened in Iteration 3
648- +------------------------------------
649- >>>
0 commit comments