Python Institute PCPP1 – Certified Professional in Python Programming 1 PCPP-32-101 Question # 4 Topic 1 Discussion
PCPP-32-101 Exam Topic 1 Question 4 Discussion:
Question #: 4
Topic #: 1
Select the true statements related to PEP 8 programming recommendations for exception handling. (Select two answers.)
A.
When designing exception hierarchies, you should focus on stating that a problem occurred, rather than programmatically trying to answer the question about what actually went wrong.
B.
You should generally use “bare” except: clauses, as they will not catch SystemExit and KeyboardInterrupt exceptions, making it more difficult to interrupt a program using keyboard shortcuts.
C.
You should derive exceptions from the Exception class, rather than from the BaseException class.
D.
You should generally limit the use of a “bare” except: clause and, whenever possible, use specific exceptions instead.
The correct answers are C and D. Custom application exceptions should normally inherit from Exception, not directly from BaseException. BaseException is intended for system-exiting exceptions such as SystemExit, KeyboardInterrupt, and GeneratorExit, so deriving ordinary errors from it can interfere with normal control flow. PEP 8 also discourages broad or bare except: clauses because they catch too much and can hide programming errors or prevent expected interruption behavior. Specific exception handling is clearer, safer, and easier to debug. Option A reverses the intended guidance: exception hierarchies should help code distinguish what went wrong programmatically. Option B is false because a bare except: can catch system-level exceptions, which is exactly why it should be avoided.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit