1try: #try to do the following
2 print("Hi there")
3except: #If what is meant to happen in (try) fails, do this.
4 print("A error happened with the code above")
1try: # put here the code that you expect to error
2 # code
3except ValueError: # if you want to catch a ValueError
4 # NOTE: you CANNOT catch a syntax error
5 # (UNLESS you are trying to execute code from a string with eval())
6
7 # code if python caught the exception
8except NameError: # you can catch multiple types of errors!
9 # TIP: you can leave the error type blank to make python catch all types of errors!
10
11 # code if another exception is caught (this is pretty much a modified if statement)
12else: # if no error has been caught do the following:
13
14 # code if no exception has been caught