Courseiva
Exceptions and File I/O →hardMultiple Choice

PCAP Exceptions and File I/O Practice Question

Exhibit

Traceback (most recent call last):
  File "app.py", line 10, in <module>
    raise ValueError('Invalid value')
ValueError: Invalid value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app.py", line 12, in <module>
    raise TypeError('Type mismatch') from None
TypeError: Type mismatch

Refer to the exhibit. What does the 'from None' clause do in the second raise statement?

⚠ Common exam trap

The PCAP exam often tests the distinction between suppressing chaining ('from None') and replacing or ignoring the original exception, leading candidates to mistakenly think the original exception is lost or ignored entirely.

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 prevents chaining of exceptions, so only the final exception is displayed.

In Python, the 'from None' clause in a raise statement explicitly suppresses exception chaining. Normally, when an exception is raised inside an except block, Python automatically chains the new exception to the original one using the __cause__ attribute. Using 'raise NewException from None' sets __cause__ to None, which prevents the interpreter from displaying the original exception's traceback, so only the final exception is shown.

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 causes the original exception to be ignored.

    Why it's wrong here

    The `from None` clause does not cause the original exception to be ignored in the sense that it never happened; the original exception is still raised and caught, and its object exists. What is suppressed is the display of the implicit chaining context in the traceback. In Python, `raise ... from None` sets `__suppress_context__` to `True`, which hides the original exception from the traceback output, but the original exception is still part of the execution history and can be accessed programmatically if a reference is kept before the new exception is raised.

  • ✓

    It prevents chaining of exceptions, so only the final exception is displayed.

    Why this is correct

    When you write `raise NewException from None`, Python's exception-handling machinery sets `__suppress_context__ = True` on the new exception. This disables the automatic chaining that normally links the current exception to the one that was being handled, which would otherwise show as "During handling of the above exception, another exception occurred" in the traceback. As a result, only the final exception's traceback is displayed, and the original, caught exception is not shown as context, though it still exists internally.

  • ✗

    It causes both exceptions to be raised simultaneously.

    Why it's wrong here

    Raising a new exception with `from None` does not cause both exceptions to be raised at once; Python's execution model can only propagate one exception at a time. The original exception has already been caught (or is being handled), and the `raise` statement deliberately replaces it as the active exception being propagated. The `from None` clause merely controls whether the original exception is shown as context in the traceback, not whether it is simultaneously raised alongside the new one.

  • ✗

    It replaces the original exception with a new one.

    Why it's wrong here

    The `from None` clause does not replace the original exception in the sense of mutating or discarding it; the original exception object remains unchanged and is still the value that was raised earlier. Instead, it sets the `__suppress_context__` flag on the *new* exception, which only affects traceback rendering. The original exception is not deleted or overwritten—it is simply hidden from the default exception output, so its role as a separate exception is preserved internally.

About these practice questions

This PCAP question is part of Courseiva's 421-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 →

How Courseiva writes practice questions · Editorial policy

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.