Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
Created November 5, 2011 03:32
Show Gist options
  • Save stephenmcd/1341065 to your computer and use it in GitHub Desktop.
Save stephenmcd/1341065 to your computer and use it in GitHub Desktop.
Trap every object method
class Foo(object):
def __getattribute__(self, name):
attr = object.__getattribute__(self, name)
if callable(attr):
def wrapper(*args, **kwargs):
try:
return attr(*args, **kwargs)
except Exception, e:
print "%s failed with exc %s" % (name, e)
attr = wrapper
return attr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment