Skip to content
This repository was archived by the owner on Apr 10, 2022. It is now read-only.

Commit 90872d2

Browse files
committed
Erase difference between raise and raise e
1 parent f5da6d1 commit 90872d2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

except_star.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,9 @@ print(
337337
# [ValueError('a'), TypeError('b'), TypeError('c'), KeyError('d')]
338338
```
339339

340-
### "raise e" vs "raise"
340+
### "raise e" and "raise"
341341

342-
The difference between bare `raise` and a more specific `raise e` is more
343-
significant for exception groups than it is for regular exceptions. Consider
344-
the following two examples that illustrate it.
345-
346-
Bare `raise` preserves the exception group internal structure:
342+
There is no difference between bare `raise` and a more specific `raise e`:
347343

348344
```python
349345
try:
@@ -356,7 +352,7 @@ try:
356352
)
357353
)
358354
except *TypeError as e:
359-
raise
355+
raise # or "raise e"
360356

361357
# would terminate with:
362358
#
@@ -370,7 +366,11 @@ except *TypeError as e:
370366
# )
371367
```
372368

373-
Whereas `raise e` would flatten the captured subset:
369+
It is important to point out that the `ExceptionGroup` bound to `e` is an
370+
ephemeral object. Raising it via `raise` or `raise e` will not cause changes
371+
to the overall shape of the `ExceptionGroup`. If the user wants to "flatten"
372+
the tree, they can explicitly create a new `ExceptionGroup` and raise it:
373+
374374

375375
```python
376376
try:
@@ -383,7 +383,7 @@ try:
383383
)
384384
)
385385
except *TypeError as e:
386-
raise e
386+
raise ExceptionGroup(*e)
387387

388388
# would terminate with:
389389
#

0 commit comments

Comments
 (0)