PCEP-30-02 · Question #239
QUESTION 267 The part of your code where you think an exception may occur should be placed inside:
The correct answer is C. the try: branch. Option C is correct because Python's try: block is specifically designed as the container for code that might raise an exception - it's the "guarded" zone where the interpreter watches for errors. If an exception occurs inside try:, Python immediately jumps to the matching…
Question
Options
- Athe except: branch
- Bthe exception: branch
- Cthe try: branch
How the community answered
(26 responses)- A15% (4)
- B12% (3)
- C73% (19)
Explanation
Option C is correct because Python's try: block is specifically designed as the container for code that might raise an exception - it's the "guarded" zone where the interpreter watches for errors. If an exception occurs inside try:, Python immediately jumps to the matching except: handler instead of crashing.
Option A is wrong because the except: branch is where you handle the exception after it's already been raised - not where the risky code lives. Option B is a distractor: exception: is not a valid Python keyword at all, so this branch doesn't exist in the language.
Memory tip: Think of try as "try this risky thing" and except as "except when it goes wrong, do this instead" - the order of the words mirrors the order of events.
Community Discussion
No community discussion yet for this question.