PCEP-30-02 · Question #237
QUESTION 265 The part of your code where the handling of an exception takes place should be placed inside:
The correct answer is A. the except: branch. In Python's exception-handling structure, the except: branch is where you place the code that responds to (handles) an exception - it only runs when the error actually occurs. Option B (exception:) doesn't exist in Python syntax at all, making it an immediate discard. Option C…
Question
Options
- Athe except: branch
- Bthe exception: branch
- Cthe try: branch
How the community answered
(42 responses)- A71% (30)
- B19% (8)
- C10% (4)
Explanation
In Python's exception-handling structure, the except: branch is where you place the code that responds to (handles) an exception - it only runs when the error actually occurs. Option B (exception:) doesn't exist in Python syntax at all, making it an immediate discard. Option C (try:) is where you place the code that might raise an exception, not where you handle it - confusing the two is the most common mistake learners make.
Memory tip: Think of it as a two-role system - try is the risky action, except is the response plan. You try something; if it fails, you except (intercept) the problem and handle it there.
try:
result = 10 / 0 # risky code goes here
except ZeroDivisionError:
print("Can't divide by zero!") # handling goes here
Community Discussion
No community discussion yet for this question.