1try:
2 # Some Code....
3except:
4 # optional block
5 # Handling of exception (if required)
6else:
7 # execute if no exception
8finally:
9 # Some code .....(always executed)
1import traceback
2
3dict = {'a':3,'b':5,'c':8}
4try:
5 print(dict[q])
6
7except:
8 traceback.print_exc()
9
10# This will trace you back to the line where everything went wrong.
11# So in this case you will get back line 5
12
13
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")