Skip to content

Instantly share code, notes, and snippets.

@billyshambrook
Created November 12, 2013 22:12
Show Gist options
  • Save billyshambrook/7439719 to your computer and use it in GitHub Desktop.
Save billyshambrook/7439719 to your computer and use it in GitHub Desktop.
class my_error_handling(object):
def __enter__(self): pass
def __exit__(self, exc_type, exc_val, exc_tb):
if issubclass(exc_type, UnicodeError):
print "annoying"
elif issubclass(exc_type, ValueError):
print "hrmm"
elif issubclass(exc_type, OSError):
print "alert sysadmin"
else:
print "other"
return True
with my_error_handling():
do_stuff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment