Files
gauvainboiche ce1f0e513a feat: Semaine 9
2026-05-15 16:24:56 +02:00

34 lines
904 B
Python

import asyncio
async def coro_a():
await asyncio.sleep(1)
raise ValueError("Error in Coro A")
async def coro_b():
await asyncio.sleep(1)
raise TypeError("Error in Coro B")
async def coro_c():
await asyncio.sleep(1)
raise IndexError("Error in Coro C")
async def main():
results = await asyncio.gather(
coro_a(),
coro_b(),
coro_c(),
return_exceptions= True # renvoie les exceptions comme des résultats
)
exceptions = [e for e in results if isinstance(e, Exception)]
if exceptions:
raise ExceptionGroup("errors", exceptions)
if __name__ == "__main__":
try:
asyncio.run(main())
except* ValueError as ve_group:
print(f"Value Error:", ve_group)
except* TypeError as te_group:
print(f"Type Error:", te_group)
except* IndexError as ie_group:
print(f"Index Error:", ie_group)