Created
May 6, 2012 22:08
-
-
Save shreyansb/2624788 to your computer and use it in GitHub Desktop.
custom exceptions in python
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
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