The fallback implemented in #2731 cannot return `obj.__dict__[name]` if the `__dict__` method has been redefined in such a way that it raises an exception when trying to access it. This commit adds a try-except block to work around this.