PCAP Exceptions and File I/O Practice Question
Which THREE of the following exception types are subclasses of OSError in Python 3?
⚠ Common exam trap
Python Institute often tests the misconception that IOError is a separate exception type in Python 3, when in fact it is an alias for OSError, and that UnicodeError or EOFError belong to the OSError family, which they do not.
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
✓
FileNotFoundError
FileNotFoundError is a direct subclass of OSError, raised when a file or directory is requested but does not exist at the given path. This is part of Python's exception hierarchy for operating system-related errors, specifically for file operations that fail due to missing resources.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
FileNotFoundError
Why this is correct
FileNotFoundError is a concrete subclass of OSError, raised when a required file or directory does not exist. Because it inherits from OSError, it is caught by an except OSError handler, yet it is distinct from PermissionError, which occurs when the item exists but access is denied. This makes it one of the three options in the OSError hierarchy.
- ✓
IOError
Why this is correct
IOError is not a separate class in modern Python; it is an alias for OSError, so the two names refer to the exact same exception type. Since issubclass(OSError, OSError) is True, IOError is considered a subclass of OSError even though it is an identity, not a derived child class. This unification happened in Python 3.3.
- ✗
UnicodeError
Why it's wrong here
UnicodeError is a subclass of ValueError, not OSError, so it sits in a completely different branch of the exception hierarchy. It groups Unicode-related conversion failures, such as UnicodeDecodeError and UnicodeEncodeError, which are semantic value problems rather than operating-system failures. Consequently, except OSError will never catch a UnicodeError.
- ✓
PermissionError
Why this is correct
PermissionError is another built-in subclass of OSError, raised when an operation is not permitted by the file system or operating system, such as attempting to write to a read-only file. Like FileNotFoundError, it inherits from OSError, but its trigger is an access-control failure, not a missing path. This distinction matters when writing targeted except clauses.
- ✗
EOFError
Why it's wrong here
EOFError is a subclass of Exception, not of OSError, and is raised when a built-in function like input() hits end-of-file without reading any data. It has no errno or strerror attributes and is not part of the OS-error hierarchy, so it is not caught by except OSError. This sets it apart from the OSError subclasses in this question.
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.