Dev HelpersOpen library
← Back

Collect exceptions from tasks

Collect exceptions from tasks. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

import asyncio
async def fail():
    raise ValueError('demo')
async def main():
    results = await asyncio.gather(fail(), return_exceptions=True)
    return [type(item).__name__ for item in results]
print(asyncio.run(main()))

Sample output

['ValueError']