PCAP Exceptions and File I/O Practice Question
A developer is implementing a custom exception for invalid data. Which class should the custom exception inherit from?
⚠ Common exam trap
A common mix-up: candidates choose `BaseException` thinking it is the most general base class, but Cisco tests the understanding that custom exceptions should inherit from `Exception` to avoid accidentally catching system-exiting exceptions like `KeyboardInterrupt`.
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
✓
Exception
The `Exception` class is the base class for all built-in, non-system-exiting exceptions in Python. Custom exceptions should inherit from `Exception` (or one of its subclasses) to ensure they are caught by generic `except Exception:` handlers and integrate properly with Python's exception hierarchy, while avoiding the system-exiting exceptions derived from `BaseException`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
RuntimeError
Why it's wrong here
RuntimeError is a concrete built-in exception class intended for generic runtime failures that have no more specific category. Subclassing it for invalid data would couple the custom exception to a distinct, unrelated failure mode, making it hard to catch separately from genuine runtime errors. The Python convention is to derive custom exceptions directly from Exception, leaving RuntimeError for its stated purpose.
- ✗
ArithmeticError
Why it's wrong here
ArithmeticError is the base class for numeric computation failures such as ZeroDivisionError and OverflowError, so it is much too narrow to represent invalid data generally. Raising or catching an exception derived from it would imply that the problem is a failed arithmetic operation, not a validation or data-integrity problem. Custom domain exceptions should instead inherit from Exception to keep the semantic meaning clear and independent from specific error categories.
- ✗
BaseException
Why it's wrong here
BaseException sits at the very top of the hierarchy and includes SystemExit, KeyboardInterrupt, and GeneratorExit, whose normal propagation should not be blocked by application-level handlers. If your invalid-data exception derived from BaseException, it would be skipped by `except Exception` blocks, so typical error-handling logic would fail to catch it. Custom exceptions must descend from Exception to be caught in normal application flows and to avoid interfering with interpreter shutdown.
- ✓
Exception
Why this is correct
Exception is the standard, recommended base class for custom exceptions because it is the root of the ordinary error hierarchy, below BaseException but above all built-in exceptions meant for program-level failures. Deriving from it ensures your invalid-data exception is caught by generic `except Exception` handlers, supports chaining with `__cause__`, and clearly communicates that it is an application-level error. This is the convention described in Python's official documentation and followed by most libraries and frameworks.
Go deeper
Related to this question
About these practice questions
This PCAP question is part of Courseiva's 169-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.