Created
February 11, 2012 21:01
-
-
Save snim2/1804191 to your computer and use it in GitHub Desktop.
Exception example in Python
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
class MyExn(Exception): | |
def __init__(self, value): | |
self.value = value | |
def __str__(self): | |
return "MyExn raised with value " + str(self.value) | |
def example(): | |
try: | |
raise MyExn(0) | |
except MyExn, e: | |
print e | |
if __name__ == '__main__': | |
example() | |
# results in: "MyExn raised with value 0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment