# ExceptionGroup: TaskGroup 中存在未处理的错误（1 个子异常）

- **ID:** `python/asyncio-taskgroup-exceptiongroup`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

asyncio.TaskGroup（3.11+）内部的异常被包装在 ExceptionGroup 中；捕获原始异常类型的调用方永远看不到它。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Catch ExceptionGroup and use except*:

try:
    async with asyncio.TaskGroup() as tg:
        tg.create_task(work())
except* ValueError as eg:
    handle(eg.exceptions)
   ```
2. **** (90% 成功率)
   ```
   Inspect sub-exceptions:

except ExceptionGroup as eg:
    for exc in eg.exceptions:
        logger.error('task failed', exc_info=exc)
   ```
3. **** (85% 成功率)
   ```
   For libraries that don't support except*, unwrap manually:

def unwrap(eg): return eg.exceptions[0] if len(eg.exceptions) == 1 else eg
   ```

## 无效尝试

- **** — The ValueError is nested inside ExceptionGroup; the outer except never matches. (90% 失败率)
- **** — Swallows the group but is bad practice; masks other failures. (70% 失败率)
- **** — Touches private state; unrelated to exception wrapping. (95% 失败率)
