Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created February 9, 2021 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azamsharp/f31601db3cab87f76220d0049b932f4d to your computer and use it in GitHub Desktop.
Save azamsharp/f31601db3cab87f76220d0049b932f4d to your computer and use it in GitHub Desktop.
# EXCEPTIONS
# try and except go together
try:
result = 1/2
number = int(input("Enter any number: ")) # e
except ZeroDivisionError:
print("Please don't divide by zero!")
except ValueError:
print("Invalid input. Please enter numbers only!")
except:
print("Opps!!")
# finally is an optional block which executes whether exception takes place or NOT
finally:
# finally block is where to close out the resources
print("FINALLY!")
else: # optional block. Fired when no exceptions are thrown
print("ELSE BLOCK")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment