PCAP Exceptions and File I/O Practice Question
A pipeline processes many small binary records. The developer writes a custom exception `class RecordError(Exception)` with an `__init__` that stores a record identifier and calls `super().__init__(message)`. A validation function raises `RecordError` for a corrupt record, and a worker catches it to log the identifier. The worker also wants the raw message to be available via `str(e)`. Which statement about this design is correct?
⚠ Common exam trap
The trap here is believing that a custom __init__ erases the default string representation, when str(e) still works as long as the subclass forwards the message to Exception.__init__.
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 stored record identifier is accessible on the caught instance, and str(e) returns the message because super().__init__ was called with it.
A custom exception that stores extra state in __init__ and delegates the message to Exception.__init__ preserves both capabilities: the identifier is available as an attribute on the instance, and the inherited __str__ renders the message from args. Overriding __init__ does not disable __str__, and subclassing Exception keeps the type catchable by broad handlers.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Because RecordError defines its own __init__, the message passed to super().__init__ is discarded and str(e) returns an empty string.
Why it's wrong here
The message is not discarded. Calling super().__init__(message) invokes Exception.__init__, which stores the argument in the args tuple, and Exception.__str__ renders that tuple when there is a single element. As long as the subclass calls super with the message, str(e) returns it normally, so this claim is technically wrong.
- ✓
The stored record identifier is accessible on the caught instance, and str(e) returns the message because super().__init__ was called with it.
Why this is correct
Assigning the identifier as an attribute in the subclass __init__ makes it available on the caught exception object, which is how the worker logs it. Delegating to Exception.__init__ with the message populates the args tuple, and the inherited __str__ returns that message. Both requirements are satisfied by this design.
- ✗
The worker must use e.args[0] instead of str(e), because custom exceptions lose the default string representation once they override __init__.
Why it's wrong here
Overriding __init__ does not remove the inherited __str__. Exception.__str__ inspects the args tuple, and super().__init__(message) sets args to a one-element tuple, so str(e) yields the message. The worker can use either str(e) or e.args[0], making the stated requirement unnecessary.
- ✗
The custom exception cannot be caught by except Exception because it does not inherit directly from BaseException.
Why it's wrong here
Inheriting from Exception places RecordError within the standard hierarchy, so except Exception catches it. Only classes derived directly from BaseException without passing through Exception, such as SystemExit and KeyboardInterrupt, escape an except Exception clause. The design shown is fully compatible with broad handlers.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCAP question from scratch — 421 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 →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.