nerdexam
Python_Institute

PCEP-30-02 · Question #238

QUESTION 266 Select the true statements about the try-except block in relation to the following example. (Choose three.) try: # Some code is here... except: # Some code is here...

The correct answer is A. If there is a syntax error in code located in the try block, the except branch will not handle it, and a SyntaxError exception will be raised instead. C. The code that follows the except statement will be executed if the code in the try clause runs into an error. D. If you suspect that a snippet may raise an exception, you should place it in the try block. A is correct because syntax errors are detected at parse time (before execution begins), so the try-except mechanism never gets a chance to catch them - Python raises SyntaxError immediately. C is correct because this is the core purpose of try-except: when the try block raises…

Question

QUESTION 266 Select the true statements about the try-except block in relation to the following example. (Choose three.) try:

Some code is here...

except:

Some code is here...

Options

  • AIf there is a syntax error in code located in the try block, the except branch will not handle it, and a SyntaxError exception will be raised instead.
  • BThe code that follows the try statement will be executed if the code in the except clause runs into an error.
  • CThe code that follows the except statement will be executed if the code in the try clause runs into an error.
  • DIf you suspect that a snippet may raise an exception, you should place it in the try block.

How the community answered

(24 responses)
  • A
    79% (19)
  • B
    21% (5)

Explanation

A is correct because syntax errors are detected at parse time (before execution begins), so the try-except mechanism never gets a chance to catch them - Python raises SyntaxError immediately.

C is correct because this is the core purpose of try-except: when the try block raises an exception at runtime, execution jumps to the except block. The code following the except keyword runs in response to that error.

D is correct because the try block is precisely where you place risky code - operations that might fail (file I/O, network calls, type conversions, etc.) so that failures can be caught and handled gracefully.

B is wrong because it inverts the logic: if the except clause itself raises an error, execution does not fall back to the try block - it propagates upward (or crashes), not "downward" to whatever follows.

Memory tip: Think of try-except as a safety net under a tightrope walker (try). The net (except) only catches falls from the rope - it can't help if the walker tripped before even stepping on (syntax error), and a hole in the net doesn't send the walker back to the rope.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice