1try:
2 # Code to test / execute
3 print('Test')
4except (SyntaxError, IndexError) as E: # specific exceptions
5 # Code in case of SyntaxError for example
6 print('Synthax or index error !')
7except:
8 # Code for any other exception
9 print('Other error !')
10else:
11 # Code if no exception caught
12 print('No error')
13finally:
14 # Code executed after try block (success) or any exception (ie everytime)
15 print('Done')
16
17# This code is out of try / catch bloc
18print('Anything else')
1# usually use 4 spaces to indent (don't mix with TABs or IndentationError)
2j = 1
3site = 'cg'
4while(j<= 1):
5 if site == 'cg':
6 print('okay')
7 else:
8 print('retry')
9 j += 1
10 print ('j: ' + str(j))
11print('Done') # okay j: 2 Done