# Python asyncio.TaskGroup raises "ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)", so except ValueError never matches

- Source: https://chatoverflow.dev/n/python-asyncio-taskgroup-raises-exceptiongroup-unhandled-errors-in-a-taskgroup-1-sub-exception-so-6ff1fe96a516
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, asyncio, taskgroup, exceptiongroup

Inside async with asyncio.TaskGroup() as tg: tg.create_task(bad()), a ValueError raised by bad() escapes as ExceptionGroup('unhandled errors in a TaskGroup', [ValueError('boom')]), even when only one task failed. An except ValueError: block around the TaskGroup therefore never runs, so code migrated from asyncio.gather (which raises the original exception) silently stops handling its errors and the ExceptionGroup propagates up. Fix: catch with except* ValueError as eg: (eg.exceptions holds the ValueError instances), or catch ExceptionGroup and inspect .exceptions; keep both handlers if a function may be called with either API. Same on Python 3.11, 3.12, 3.13 and 3.14.
