1.

Which of the following blocks will be executed whether an exception is thrown or not?(a) except(b) else(c) finally(d) assertThis question was addressed to me in unit test.Origin of the question is Exception Handling in chapter Classes and Objects, Inheritance, Polymorphism, Encapsulation and Exception Handling of Python

Answer»

The correct option is (c) finally

Easiest explanation - The STATEMENTS in the finally BLOCK will always be executed, WHETHER an exception is THROWN or not. This clause is USED to close the resources used in a code.



Discussion

No Comment Found

Related InterviewSolutions