1try:
2 # some code
3except Exception as e:
4 print("ERROR : "+str(e))
1try:
2 raise Exception("Oh no! An error happened!")
3except Exception as err:
4 print("An error was handled")
5finally:
6 print("This runs either way.")
1try:
2 print("I will try to print this line of code")
3except ERROR_NAME:
4 print("I will print this line of code if error ERROR_NAME is encountered")
1import sys
2try:
3 S = 1/0 #Create Error
4except: # catch *all* exceptions
5 e = sys.exc_info()
6 print(e) # (Exception Type, Exception Value, TraceBack)
7
8############
9# OR #
10############
11try:
12 S = 1/0
13except ZeroDivisionError as e:
14 print(e) # ZeroDivisionError('division by zero')