Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created May 6, 2012 22:08
Show Gist options
  • Save shreyansb/2624788 to your computer and use it in GitHub Desktop.
Save shreyansb/2624788 to your computer and use it in GitHub Desktop.
custom exceptions in python
In [1]: def raise_exception():
...: raise Exception('the base exception')
...:
In [2]: try:
...: raise_exception()
...: except Exception, e:
...: print "caught: %s" % e
...:
caught: the base exception
In [3]: class CustomException(Exception):
...: pass
...:
In [4]: try:
...: raise CustomException('a custom exception')
...: except CustomException, e:
...: print "caught: %s" % e
...:
caught: a custom exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment