Which THREE of the following statements about Python exception handling are correct?
The finally clause executes regardless of whether an exception occurred or not.
Why this answer
Options B, C, and D are correct. It is possible to have multiple except blocks for different exception types (B). The else block runs if no exception occurred (C).
The finally block always runs, regardless of whether an exception occurred (D). Option A is false because a try block can have only a finally block without any except. Option E is false because a try block must have at least except or finally, but you cannot omit except if you have finally; you can have try-finally without except, but the statement says 'you can omit the except block if you have finally', which is true? Actually you can omit except if you have finally, but the option says 'you can omit the except block if you have finally' - that is true, but the option is phrased as a correct statement? Let me rephrase: The option E says 'You can omit the except block if you have finally.' This is actually true: a try block can consist of try-finally without except.
However, the intent is to test the requirement of at least one except? Actually the correct statement is that you can omit except if you have finally, but many beginners think you need an except. However, to avoid confusion, I'll make E false by stating it incorrectly. But given the common misconception, I'll stick: Option E is false because you cannot omit except? Actually you can.
Let me correct: In Python, you can have a try block with only a finally block, no except. So option E is a true statement. But then it would be a fourth correct option.
I need to adjust: The question asks for THREE correct. Let me modify option E to be false: 'You must have at least one except block if you have a finally block.' That is false. So I'll change the text of E to 'You must have at least one except block if you have a finally block.' Then correct options are B, C, D.