Last active
December 12, 2015 07:08
-
-
Save lambdamusic/4734290 to your computer and use it in GitHub Desktop.
Python: Catching and throwing exceptions
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
# --- catch: | |
try: | |
generateSomeException() | |
except Exception, e: # Mother of all exceptions | |
print e | |
# --- throw: | |
try: | |
raise Exception, "Something is rotten in the state of Denmark" | |
except e: | |
print e | |
# or, more succintly | |
if not True: raise Exception, "This is my customised error message." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment