Can I place the finally block before except block ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can I place the finally block before except block ?

Means if I don't want any type of error then can I remove the exception suite and just type the finally block

17th Mar 2019, 6:39 AM
Shikhar Nagle
Shikhar Nagle - avatar
2 Answers
+ 2
You shouldĀ placeĀ those statements in thisĀ blockĀ that must be executed always. ... In normal case when there is noĀ exceptionĀ in tryĀ blockĀ then thefinally blockĀ is executed after tryblock. However if anĀ exceptionĀ occurs then theĀ catch blockĀ is executedbefore finally block.. šŸ˜‰
17th Mar 2019, 6:58 AM
Max Andal
Max Andal - avatar
+ 2
You still need the exception block only that it is empty in most language (pass in Python).
17th Mar 2019, 7:16 AM
Gordon
Gordon - avatar