class X:

    def __del__(self):
        print('deleting')

def error():
    X().wrong
old_hook = sys.excepthook

def did_you_mean_hook(type, exc, tb):
    print('Error!')
sys.excepthook = did_you_mean_hook
error()
How to get hold of the object missing an attribute