DataUpdateCoordinator and exceptions

I’m having a problem where I can’t catch exceptions on code that is run in the update of DataUpdateCoordinator. Here is a chunk of my code:

def foo():
    raise ValueError("Testing testing testing")

class ECDataUpdateCoordinator(DataUpdateCoordinator):
...
    async def _async_update_data(self):
        """Fetch data from EC."""
        try:
            await self._hass.async_add_executor_job(foo)
        except Exception as exc:
            print("Exception caught")

        return self.ec_data

I never get the print happening. I always get the traceback from the exception.

In looking at the update coordinator code, I see the _async_update_data is in a try/except block, hence catching the exceptions. Makes sense. What I don’t get is that other integrations (e.g.: Brother and Shelly) have try/except around their update. I’m assuming that they are caught and handled - I just can’t seem to catch them.

I’m missing something and it could be my assumptions that other integrations are doing the right thing.

Any suggestions or thoughts? Am I even supposed to be catching exceptions if using a DataUpdateCoordinator?

Long shot, can you try handling exception inside foo?

Thanks! No, foo is my simplification of a library call that raises exceptions.

What I think I’ve discovered is that I can do except ValueError and that is caught. The generic except Exception is not caught. That’s in this simple case.

When I put the library back into play its exceptions get raised and not caught even when in this try/except block.

So ValueError is not caught by generic exception? Really?

In this case yes. The _async_update_data is being called from the DataUpdateCoordinator class where the call is already in a try/except block. Some interaction I don’t understand is happening.