PCAP Exceptions and File I/O Practice Question
Exhibit
Traceback (most recent call last):
File "test.py", line 3, in <module>
raise ValueError("Invalid value")
ValueError: Invalid value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 5, in <module>
raise TypeError("Type mismatch") from None
TypeError: Type mismatchRefer to the exhibit. What is the effect of using 'from None' in the raise statement?
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
✓
It suppresses the exception chain and only shows the TypeError
Using 'from None' suppresses the chaining of exceptions, so the original ValueError is not shown in the traceback.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It re-raises the original ValueError
Why it's wrong here
Re-raising the original ValueError would require an active exception handler and a bare `raise` statement, which rethrows the exception currently being handled. In this code, a brand-new TypeError is created and raised with `from None`; the original ValueError is neither re-thrown nor propagated. The `from None` clause only controls how the new exception's context is displayed, not which exception is raised.
- ✗
It causes a syntax error
Why it's wrong here
The `raise` statement in Python allows an optional `from` clause, and the keyword `None` is a valid expression after `from`, specifically to indicate context suppression. The Python grammar explicitly supports `raise ... from None`, so no SyntaxError is raised. The misconception arises because `from` is usually followed by an exception object, but `None` is a documented special case.
- ✓
It suppresses the exception chain and only shows the TypeError
Why this is correct
Using `from None` in a `raise` statement sets the `__suppress_context__` attribute of the exception to `True`. When the TypeError propagates, Python's default exception handler checks this flag and, because it is true, omits the implicit display of the original ValueError and its traceback. The final output therefore contains only the TypeError, either in the interactive shell or in a captured traceback.
- ✗
It chains the TypeError to the original ValueError
Why it's wrong here
Chaining occurs when `raise ... from cause` assigns the `__cause__` attribute, or when an exception occurs during handling and Python automatically sets `__context__`. With `from None`, Python instead sets `__suppress_context__ = True`, which tells the traceback formatter not to show any context. Thus the TypeError is not chained to the ValueError; the chain is deliberately broken and hidden.
Go deeper
Related to this question
About these practice questions
One of 169 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.