+ 1
Can we remove finally: ?
What is the difference between these codes : Code 1: try: x except: y finally: z Code 2: try: x except: y z
2 Respostas
+ 4
You can remove finally if your application does not need to perform any operation if exception raised while handling exception as shown below.
try:
raise ValueError("code1")
except ValueError as e:
print("code 1 except")
raise ValueError("code11")
finally:
print('code 1 finally' )
Code under finally block will be executed even if the exception raised while handling exception. Run above code and check with and without finally block.
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 no
I meant the difference of them in output