Last active
March 7, 2023 05:34
-
-
Save ROBOMASTER-S1/163632d30b2e5412eb8388b64714ac91 to your computer and use it in GitHub Desktop.
Raise Some Errors Python Program Example: Created by Joseph C. Richardson
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
# Raise a list of possible errors to test in Python programs. | |
# Created by Joseph C. Richardson, GitHub.com | |
try: | |
print('Raising a list of possible errors to test:') | |
raise Exception | |
raise ValueError | |
raise TypeError | |
raise NameError | |
raise IndexError | |
raise MemoryError | |
except Exception: | |
print('Exception:') | |
except ValueError: | |
print('ValueError:') | |
except TypeError: | |
print('TypeError:') | |
except NameError: | |
print('NameError:') | |
except IndexError: | |
print('IndexError:') | |
except MemoryError: | |
print('MemoryError:') | |
finally: | |
print('finally always executes no matter the outcome.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment