Courseiva
Exceptions and File I/O →hardMultiple Select

PCAP Exceptions and File I/O Practice Question

Which THREE of the following are true about Python's exception hierarchy?

⚠ Common exam trap

Python Institute often tests the misconception that `GeneratorExit` inherits from `Exception` (it actually inherits from `BaseException`), and that `IOError` is a separate class from `OSError` (it is an alias in Python 3).

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

✓

KeyboardInterrupt inherits from BaseException.

`KeyboardInterrupt` inherits directly from `BaseException`, not from `Exception`. This design ensures that `KeyboardInterrupt` (raised by Ctrl+C) is not caught by a generic `except Exception:` clause, allowing the program to be interrupted even when broad exception handling is in place.

Answer analysis

Option-by-option breakdown

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

  • ✓

    KeyboardInterrupt inherits from BaseException.

    Why this is correct

    KeyboardInterrupt is a true statement because KeyboardInterrupt is a direct subclass of BaseException, not of Exception. This design ensures that a KeyboardInterrupt triggered by Ctrl+C propagates outward even when code has a broad `except Exception:` handler. Catching it accidentally would prevent clean interruption and could leave the program in an inconsistent state, so it must be caught explicitly with `except KeyboardInterrupt` or a bare `except:`. The hierarchy deliberately places user-initiated termination outside the ordinary exception family.

  • ✓

    SystemExit inherits from BaseException.

    Why this is correct

    SystemExit is also a true statement because SystemExit inherits directly from BaseException, bypassing Exception. It is raised by `sys.exit()` to request interpreter shutdown, and by keeping it outside Exception, Python prevents generic exception handlers from swallowing exit requests. A bare `except Exception:` will not intercept SystemExit, allowing cleanup and termination logic in `finally` blocks to run as intended. This separation reflects that SystemExit is not an application error but a controlled exit mechanism.

  • ✗

    IOError is a separate class from OSError.

    Why it's wrong here

    IOError is a separate class from OSError is false because in Python 3, IOError is simply an alias for OSError, not a distinct class. Both names refer to the exact same class object, so code using either name catches identical exceptions. This unification happened in Python 3 (and was already the case in Python 2 for practical purposes) to streamline operating-system-related error handling. Treating them as separate would misrepresent the modern exception hierarchy where the name IOError exists only for backward compatibility.

  • ✓

    ZeroDivisionError inherits from ArithmeticError.

    Why this is correct

    ZeroDivisionError is a true statement because ZeroDivisionError inherits from ArithmeticError, which in turn inherits from Exception. ArithmeticError groups numeric errors like integer division by zero, overflow, and floating-point failures under one common parent. Since ArithmeticError is a subclass of Exception, ZeroDivisionError is catchable by a general `except Exception:` handler, making it a standard runtime error rather than a system-level interruption. This placement allows programmers to handle all arithmetic failure modes uniformly while still being able to catch more specific subclasses separately.

  • ✗

    GeneratorExit inherits from Exception.

    Why it's wrong here

    GeneratorExit is a false statement because GeneratorExit inherits directly from BaseException, not from Exception. This exception is raised when a generator's `close()` method is called, signaling that the generator should exit from its current suspension point. By placing GeneratorExit outside Exception, Python prevents ordinary `except Exception:` blocks inside the generator from unintentionally catching the exit signal and continuing execution. The generator must either re-raise it or let it propagate to properly shut down, distinguishing it from regular runtime errors.

About these practice questions

One of 421 original PCAP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.