Created
November 12, 2013 22:12
-
-
Save billyshambrook/7439719 to your computer and use it in GitHub Desktop.
Context error handling - http://pyvideo.org/video/883/decorators-and-context-managers
This file contains hidden or 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
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