Skip to content

Instantly share code, notes, and snippets.

@craigcalef
Created February 22, 2012 04:36
Show Gist options
  • Save craigcalef/1881442 to your computer and use it in GitHub Desktop.
Save craigcalef/1881442 to your computer and use it in GitHub Desktop.
Exception printing decorator
import traceback
def printexceptions(f):
def a(*args, **kwargs):
try:
return f(*args, **kwargs)
except:
traceback.print_exc()
return a
@printexceptions
def testfunction(asdf):
raise Exception("This is an exception.")
@printexceptions
def testfunction2():
return 2
try:
testfunction('derpaderp')
except:
print "This exception handler should never be reached."
assert(testfunction2() == 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment