PCAP Exceptions and File I/O Practice Question
Which of the following correctly raises a new exception while preserving the original traceback?
⚠ Common exam trap
Python Institute often tests the distinction between re-raising the same exception (bare `raise` or `raise original_exception`) and raising a new exception with chaining (`raise ... from original_exception`), trapping candidates who think any `raise` preserves the traceback.
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
✓
raise ValueError('new') from original_exception
The `raise ... from original_exception` syntax in Python allows you to raise a new exception while chaining it to the original exception, preserving the original traceback. This is essential for debugging, as it shows both the new error and the root cause.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
raise original_exception
Why it's wrong here
Raising `original_exception` directly propagates that exact exception object, not a new exception. Python's `raise` statement with an expression evaluates the expression and raises that instance, so the exception type and original traceback are preserved. This means it cannot satisfy a need to raise a different exception such as `ValueError`; it merely re-raises the original.
- ✗
raise ValueError('new')
Why it's wrong here
This creates a brand-new `ValueError` instance, but it omits the `from` clause that explicitly links the new exception to `original_exception`. If executed while an exception is being handled, Python will automatically set the new exception's `__context__` to the original and show a "During handling" traceback; however, `__cause__` remains `None` and the original is not marked as the direct cause. Explicit chaining requires the `from` keyword.
- ✓
raise ValueError('new') from original_exception
Why this is correct
This is the correct form for explicitly chaining a new exception to an existing one. The `from original_exception` clause makes Python assign the original to the new `ValueError`'s `__cause__` attribute, causing the traceback to present the original as the direct cause of the new exception. This preserves the debugging information from the original failure while still allowing a distinct exception type to be raised.
- ✗
raise
Why it's wrong here
A bare `raise` cannot create a new exception; it is valid only inside an `except` block, where it re-raises the currently handled exception with its original traceback. Outside of an exception handler, it raises `RuntimeError("No active exception")`. Therefore, it is not a way to raise a new `ValueError` and is incorrect when the goal is to wrap the original in a new exception.
Visual reference
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 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.