nerdexam
Python_Institute

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…

PEP and Best Practices

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)
  • A
    8% (5)
  • B
    5% (3)
  • C
    88% (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

#PEP 8#exception handling#bare except#BaseException

Community Discussion

No community discussion yet for this question.

Full PCPP-32-101 Practice