Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
Last active December 12, 2015 07:08
Show Gist options
  • Save lambdamusic/4734290 to your computer and use it in GitHub Desktop.
Save lambdamusic/4734290 to your computer and use it in GitHub Desktop.
Python: Catching and throwing exceptions
# --- 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