DEV Community

loading...

Discussion on: Catching every single exception with Python

Collapse
rafaacioly profile image
Rafael Acioly

Nice!

I'm facing some weird problem with exception handler when it comes to catch the message from CancelledError from asyncio package, even if i do this;

try:
    something()
except asyncio.CancelledError as error:
    logger.info(f"Cancelled error:{error}")
except Exception as error:
    # something

The logged message is aways: "Cancelled error:" (empty error message), have you faced this problem?

Collapse
moshe profile image
Moshe Zada

If your use case is logging the exception use logger.exception("Cancelled error") which logs the exception and the stacktrace