+ 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

20th Jun 2020, 5:06 PM
Mr.Lightning
Mr.Lightning - avatar
4 RĂ©ponses
+ 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.
20th Jun 2020, 6:13 PM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar
20th Jun 2020, 5:26 PM
Mr.Lightning
Mr.Lightning - avatar