+ 2
Why do even we have to use Finally ?? we can just write the code outside of "except" block...!
2 Antworten
+ 5
In Finally-block you write the code that needs to be executed whether your program raises an exception or not. For example, suppose you have a file opened and due to some problem your program terminates. Then your file needs to be closed anyhow. There comes "Finally-block" to the rescue.
0
Yes, you can, but the code after the except block will not get executed if an exception is thrown that is not handled by any except block, if the function returns prematurely, or if the try block is in a loop and you jump out via break. Code in the finally block will get executed in these cases, too (= no matter what!).