Question 476 of 169
PCAP Exceptions and File I/O Practice Question
A developer is working on a data pipeline that processes files from untrusted sources. The pipeline should catch and log any exception, but also ensure that sensitive information from the exception (e.g., file paths) is not exposed to end users. Which approach balances security and debugging?
⚠ Common exam trap
Python Institute often tests the distinction between logging exceptions for debugging versus exposing them to users, and the trap here is that candidates may choose Option A (re-raise) thinking it preserves the exception chain, but they overlook the security requirement to hide sensitive details from end users.
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
✓
Catch the exception, log the full traceback, then raise a custom generic exception.
It balances security and debugging: the full traceback is logged for developers (preserving debugging details like file paths), while a custom generic exception is raised to end users, preventing sensitive information from being exposed. This approach follows the principle of least privilege for error handling, ensuring that internal details are not leaked to untrusted sources.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Catch the exception and re-raise the same exception.
Why it's wrong here
Catching and re-raising the same exception merely forwards the original traceback and message unchanged. If the pipeline's top-level handler is not secure, sensitive internals such as file paths, database queries, or model parameters may be exposed to the client. It also forfeits the chance to add contextual information and does not satisfy the goal of decoupling internal failure details from external responses.
- ✗
Catch the exception, log it, and suppress it silently.
Why it's wrong here
Silently suppressing an exception after logging creates a false sense of reliability because the pipeline may appear to complete while records are actually missing or corrupt. Operators are unlikely to monitor raw logs in real time, so critical failures can go unnoticed until downstream consumers report bad data. Swallowing exceptions also violates the fail-loud principle, as a partially processed dataset is often worse than an explicit error.
- ✓
Catch the exception, log the full traceback, then raise a custom generic exception.
Why this is correct
This is the recommended approach because it separates internal diagnostics from user-facing failure information. Logging the full traceback preserves the exact stack, exception types, and local context for developers, while raising a custom generic exception like PipelineProcessingError prevents sensitive implementation details from leaking. Using a custom exception also gives callers a stable interface for retry and alerting logic without coupling them to low-level I/O or network exceptions.
- ✗
Catch the exception and print it to the console.
Why it's wrong here
Printing the exception to the console places unredacted error details where end users or shared log viewers may unintentionally see them, creating an information-disclosure risk. Console output typically contains only the exception message, not the full stack, so developers lose diagnostic value. It also bypasses standardized logging facilities, making errors harder to correlate, filter, and alert on compared with a proper logging framework.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.