PCPP-32-101 · Question #73
Select the true statements related to PEP 8 programming recommendations for exception handling. (Choose two.)
The correct answer is C. You should generally limit the use of a "bare" except: clause and, whenever possible, use D. You should derive exceptions from the Exception class, rather than from the BaseException. PEP 8 advises avoiding bare except: clauses because they catch all exceptions, including system-exiting ones, which can make debugging and program interruption harder. Custom exceptions should inherit from Exception instead of BaseException to avoid catching system-exiting…
Question
Select the true statements related to PEP 8 programming recommendations for exception handling. (Choose two.)
Options
- AYou should generally use "bare" except: classes, as they will not catch SystemExit and
- BWhen designing exception hierarchies, you should focus on stating that a problem occurred, rather
- CYou should generally limit the use of a "bare" except: clause and, whenever possible, use
- DYou should derive exceptions from the Exception class, rather than from the BaseException
How the community answered
(65 responses)- A8% (5)
- B5% (3)
- C88% (57)
Explanation
PEP 8 advises avoiding bare except: clauses because they catch all exceptions, including system-exiting ones, which can make debugging and program interruption harder. Custom exceptions should inherit from Exception instead of BaseException to avoid catching system-exiting exceptions like SystemExit and KeyboardInterrupt.
Topics
Community Discussion
No community discussion yet for this question.