Python Exception Hierarchy — Understanding Subclass Relationships
Which of the following exception classes is NOT a direct subclass of Exception in Python?
⚠ Common exam trap
Python Institute often tests the distinction between BaseException and Exception, trapping candidates who assume all built-in exceptions inherit from Exception, when in fact SystemExit, KeyboardInterrupt, and GeneratorExit are direct subclasses of BaseException.
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
✓
SystemExit
SystemExit is not a direct subclass of Exception; it inherits from BaseException instead. This is because SystemExit, along with KeyboardInterrupt and GeneratorExit, is intended to signal that the interpreter should exit, and catching it with a generic except Exception clause would be inappropriate. All other options (IOError, StopIteration, ValueError) are direct subclasses of 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.
- ✗
IOError
Why it's wrong here
IOError is not the right answer because it is merely an alias for OSError, and OSError is a subclass of Exception. Since Exception itself is a direct subclass of BaseException, any class inheriting from Exception—including OSError and thus IOError—cannot be the odd one out in this context. Therefore, IOError is squarely within the normal exception hierarchy, not a BaseException-only branch.
- ✓
SystemExit
Why this is correct
SystemExit is the correct answer because it inherits directly from BaseException rather than from Exception. Unlike IOError, StopIteration, and ValueError—all of which are descendants of Exception—SystemExit bypasses the Exception class entirely. This deliberate design lets SystemExit (along with KeyboardInterrupt) propagate even when code catches Exception, so it is the only listed class that is not a subclass of Exception.
- ✗
StopIteration
Why it's wrong here
StopIteration is incorrect for this question because it is explicitly a subclass of Exception. It is a standard exception used to signal the end of an iterator, and like other regular exceptions it falls under the Exception branch of the BaseException hierarchy. Since it descends from Exception, it does not share the special status of SystemExit, which avoids Exception entirely.
- ✗
ValueError
Why it's wrong here
ValueError is not the correct choice because it is a direct subclass of Exception, making it a typical member of the regular exception hierarchy. It is raised for operation-specific errors, such as when a function receives an argument of the right type but an inappropriate value. Because it inherits from Exception, it is definitely a subclass of Exception, unlike SystemExit, which stems from BaseException instead.
Go deeper
Related to this question
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 →
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.