-
-
Save azamsharp/3e4869d8fc0dad8ab1a4207527d4908b to your computer and use it in GitHub Desktop.
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
# Exceptions | |
def ask_user_for_input(): | |
print("asking user for input") | |
number = int(input("Enter number: ")) | |
try: # capturing runtime errors | |
#ask_user_for_input() | |
#result = 1/0 | |
result = 4/2 | |
# number = int(input("Enter number: ")) # ValueError | |
#with open("guests.txt") as file: | |
# file.read() | |
except ZeroDivisionError: | |
print("Hey don't divide by zero") | |
except ValueError: | |
print("Please only enter numbers..") | |
except FileNotFoundError: | |
print("File does not exists!") | |
except: | |
print("Opps something happened!") | |
else: #fired when no exception has happened.. | |
print("Everything is good!") | |
finally: # fired when exception happens and also fired when exception does not happen | |
# clean up resource | |
# database connections/ socket connections/ file io | |
print("FINALLY BLOCK FIRED") | |
print("hey what about me!!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment