PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A developer is writing a robust script that must handle file reading errors. The script should catch only I/O-related exceptions (e.g., FileNotFoundError, PermissionError) and let other exceptions propagate. Which exception handling structure is best suited?
⚠ Common exam trap
The PCEP exam often tests the misconception that a single `except Exception:` is sufficient for selective handling, but candidates fail to realize it catches all `Exception` subclasses, including non-I/O ones, thus violating the requirement to let other exceptions propagate.
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
✓
Use multiple except blocks for specific exception types
Using multiple `except` blocks for specific exception types (e.g., `FileNotFoundError`, `PermissionError`) allows the script to catch only I/O-related exceptions while letting all other exceptions propagate unhandled. This matches the requirement precisely, as each `except` clause targets a distinct exception class, and any unlisted exception will not be caught, preserving the intended error propagation behavior.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use a single bare except: clause
Why it's wrong here
A bare except catches all exceptions, including SystemExit and KeyboardInterrupt, which is not recommended.
- ✗
Use except: and then re-raise the exception
Why it's wrong here
Re-raising after bare except does not prevent catching critical exceptions in the first place.
- ✓
Use multiple except blocks for specific exception types
Why this is correct
This targets only the expected exceptions, letting others propagate as intended.
- ✗
Use except Exception: as the only handler
Why it's wrong here
This catches all exceptions derived from Exception, still too broad and may mask unexpected errors.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 498-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 PCEP 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 PCEP exam.