PCAP Exceptions and File I/O Practice Question
Which TWO statements about exception handling in Python are correct? (Select exactly 2.)
⚠ Common exam trap
Python Institute often tests the misconception that the else block runs after an exception or that except order is irrelevant, leading candidates to select B or E instead of recognizing the correct behavior of tuple-based except clauses and the unconditional execution of finally.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
A single except clause can catch multiple exception types by passing a tuple of exceptions.
Python's except clause accepts a tuple of exception types, allowing a single handler to catch multiple exception types. For example, `except (ValueError, TypeError):` will catch either exception, which is a concise way to handle related errors without duplicating code.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
A single except clause can catch multiple exception types by passing a tuple of exceptions.
Why this is correct
A single except clause can catch multiple exception types by passing a tuple, e.g., `except (ValueError, TypeError) as e:`. The raised exception is matched against the tuple using `isinstance()`, so any exception that is an instance of one of the listed types (including subclasses) is handled. Parentheses are mandatory because the syntax requires a literal tuple; writing `except ValueError, TypeError:` is invalid in Python 3. This lets you group unrelated exceptions that need identical handling into one clause.
- ✗
The order of except clauses does not matter because only one will match.
Why it's wrong here
The order of except clauses is significant because Python evaluates them from top to bottom and executes the first matching handler; it does not search for the 'best' match. If a broader exception type like `except Exception` appears before a more specific one like `except ValueError`, the broader clause will catch the ValueError, and the narrower clause will never run. This is a common source of bugs, so specific exceptions must always precede more general ones.
- ✓
The finally block always executes, even if the try block contains a return statement.
Why this is correct
The `finally` block is guaranteed to execute regardless of how the `try` block exits, including when a `return`, `break`, or `continue` statement is executed, or when an unhandled exception propagates. In the case of a `return`, the expression's value is evaluated, then the `finally` block runs, and then the function actually returns the saved value. If `finally` itself contains a `return` or `raise`, it overrides the prior control flow, which is a subtle but important pitfall.
- ✗
An else block can be used without any except blocks in a try statement.
Why it's wrong here
In Python's grammar, an `else` clause in a `try` statement is only valid when at least one `except` clause is present; a `try` block followed directly by `else` is a syntax error. The grammar defines `try1_stmt` with a mandatory nonempty sequence of `except` blocks before the optional `else` and `finally`, while `try2_stmt` allows `try`...`finally` but no `else`. Therefore, you cannot use an `else` block without first having an `except`.
- ✗
The else block in a try statement executes only if an exception was raised.
Why it's wrong here
The `else` block in a `try` statement executes only when the `try` block finishes without raising any exception; it is skipped if an exception is raised and handled by an `except` clause. Its purpose is to contain code that should run only on success, so that this code is not accidentally protected by the preceding `except` handlers. Thus, saying it executes only if an exception was raised is exactly backwards.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.