← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

Exception Groups & except*

Python Python 3.11+ Advanced
debt(d7/e3/b3/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7) — mypy/ruff don't reliably flag 'only first exception caught' patterns in asyncio.gather; missed concurrent failures typically surface in code review or when failures slip through silently.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3) — quick_fix is replacing asyncio.gather with TaskGroup and using except* blocks, a localized pattern swap within the affected async code paths.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3) — applies primarily to async/concurrent code sections; doesn't shape the whole system but adds ongoing handling complexity wherever TaskGroup is used.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7) — per misconception, developers assume except* is a drop-in for except; it contradicts familiar exception semantics by operating on groups and leaving unmatched exceptions to propagate.

About DEBT scoring →

Also Known As

ExceptionGroup except* Python 3.11 exceptions concurrent exceptions ExceptionGroup Python

TL;DR

Python 3.11+ ExceptionGroup allows multiple concurrent exceptions to be raised simultaneously — essential for asyncio.TaskGroup where all tasks run even if some fail.

Explanation

ExceptionGroup (Python 3.11) wraps multiple exceptions raised simultaneously. except* syntax catches specific exception types from the group while letting unmatched exceptions propagate. asyncio.TaskGroup (Python 3.11) runs all tasks and collects all failures in an ExceptionGroup — unlike asyncio.gather which only surfaces the first failure. The except* handler receives an ExceptionGroup containing only the matching exceptions.

Common Misconception

except* catches individual exceptions like except — except* specifically handles ExceptionGroup and collects all matching exceptions from the group; it does not replace regular except for single-exception handling.

Why It Matters

asyncio.TaskGroup exposes all concurrent failures simultaneously — without ExceptionGroup, only the first failure from concurrent tasks would be visible, hiding other errors.

Common Mistakes

  • Using except* for single exceptions — it is specifically for ExceptionGroup
  • Not handling remaining unmatched exceptions — they still propagate
  • Forgetting asyncio.TaskGroup requires Python 3.11+ — use asyncio.gather for older versions
  • Not iterating eg.exceptions to see individual exception details

Code Examples

✗ Vulnerable
# asyncio.gather — only first error visible:
async def run_all():
    results = await asyncio.gather(task1(), task2(), task3())
    # If task1 and task3 both fail:
    # Only task1's error is raised — task3's error is silently lost
✓ Fixed
# asyncio.TaskGroup — all errors collected:
async def run_all():
    async with asyncio.TaskGroup() as tg:
        t1 = tg.create_task(task1())
        t2 = tg.create_task(task2())
        t3 = tg.create_task(task3())
    # All tasks ran; both failures collected in ExceptionGroup

try:
    await run_all()
except* ValueError as eg:
    for exc in eg.exceptions:
        print(f'ValueError from task: {exc}')
except* ConnectionError as eg:
    for exc in eg.exceptions:
        print(f'Connection failed: {exc}')

Added 16 Mar 2026
Edited 22 Mar 2026
Views 108
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 2 pings S 1 ping S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping S 2 pings S 1 ping M 0 pings T 1 ping W 2 pings T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M
No pings yet today
SEMrush 1
Amazonbot 17 ChatGPT 7 Google 7 Perplexity 6 PetalBot 6 Ahrefs 5 SEMrush 5 Bing 3 Scrapy 2 Brave Search 2 Unknown AI 1 Claude 1 Meta AI 1 Sogou 1 Twitter/X 1 Applebot 1
crawler 65 crawler_json 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Python general Python is a programming language known for readable syntax and versatility, used for web development, data science, automation, and more.

Python's gentle learning curve makes it an ideal first language, while its vast ecosystem keeps it relevant for machine learning, APIs, and DevOps. Skills transfer directly to professional environments because Python runs in production at companies of every size.

💡 When Python throws IndentationError, check that every block uses the same whitespace style—pick spaces (preferably 4) and stick with them everywhere.

Ask Codex about Python →
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Use Python 3.11 ExceptionGroups with except* to handle multiple concurrent exceptions — essential when running parallel async tasks where several may fail simultaneously
📦 Applies To
python 3.11 web cli
🔗 Prerequisites
🔍 Detection Hints
asyncio.gather() catching only first exception; ignoring failures from asyncio.TaskGroup; no handling for concurrent task failures
Auto-detectable: ✓ Yes mypy ruff
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Medium Context: Function Tests: Update


✓ schema.org compliant