Courseiva
Exceptions and File I/OeasyMultiple ChoiceObjective-mapped

PCAP Exceptions and File I/O Practice Question

In Python, if you have a try block followed by an except clause that catches all exceptions, which of the following is true about the else clause?

⚠ Common exam trap

Candidates often confuse the `else` clause with a second chance to handle exceptions or think it runs unconditionally before `finally`, when in fact it is strictly tied to the successful execution of the `try` block and is skipped entirely if any exception occurs.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The else clause runs only if no exception is raised in the try block.

In Python, the `else` clause in a `try` statement executes only if no exception was raised in the `try` block. This is true regardless of whether the `except` clause catches all exceptions (e.g., bare `except:` or `except Exception:`). The `else` block is specifically designed for code that should run only when the `try` block completes successfully without any exception.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The else clause runs only if no exception is raised in the try block.

    Why this is correct

    The else clause is part of a try/except/else/finally compound statement. It executes only when the try block completes without raising any exception, meaning control flows to else immediately after the last statement in try. If an exception occurs, else is skipped and control jumps to a matching except handler instead. This makes else ideal for code that should run only on success, such as logging successful completion or proceeding with a computed result.

  • The else clause runs only if an exception occurs.

    Why it's wrong here

    This statement reverses the true semantics of try/except/else. When an exception is raised inside the try block, Python abandons the else clause and instead searches for a matching except handler; only if no exception occurs will else run. Since the else clause is explicitly for the no-exception path, asserting it runs only on exception is factually backward and would render the except handler redundant.

  • The else clause runs before the finally block regardless of exceptions.

    Why it's wrong here

    While the finally block does execute unconditionally after either try completion or an except handler, the else clause is not unconditional. The else clause runs only if the try block exits normally without an exception; if an exception occurs, else never executes, even though finally still will. Thus the phrase 'regardless of exceptions' incorrectly groups else with finally, when in reality else is conditional and exists solely for the successful outcome.

  • The else clause is used to specify additional exception handlers.

    Why it's wrong here

    The else clause is not a mechanism for declaring additional exception handlers; exception handling is exclusively done using except clauses with optional exception types. Rather, else is a control-flow construct that executes only after a successful try block, and it cannot intercept exceptions since it runs after exception screening is complete. An exception raised inside else would propagate outward or be caught by an enclosing try block, never by the same statement's except clauses.

About these practice questions

Courseiva writes every PCAP question from scratch — 169 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.