Created
February 22, 2012 04:36
-
-
Save craigcalef/1881442 to your computer and use it in GitHub Desktop.
Exception printing decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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