Courseiva

FC0-U71 Software Development Concepts Practice Question

A developer writes a function that opens a file, reads its contents, and then returns the data. If the file does not exist, the program should display a friendly message instead of terminating abruptly. Which approach best handles this situation?

⚠ Common exam trap

The trap here is believing that documenting the failure or retrying automatically is equivalent to handling it, when only catching the exception lets the program respond in a controlled way.

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

✓

Wrap the file read in a try-catch block and handle the file-not-found exception

When an operation can fail for a predictable reason such as a missing file, structured exception handling allows the program to recover gracefully. The try block contains the risky read, and the catch block intercepts the specific error and presents a friendly message. Comments, constants, and unbounded retries do not intercept the failure, so they cannot prevent the abrupt termination.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Wrap the file read in a try-catch block and handle the file-not-found exception

    Why this is correct

    A try-catch block lets the code attempt the file read and intercept the exception raised when the file is missing. The catch block can then display the friendly message and allow the program to continue. This is the standard structured way to handle anticipated runtime errors without crashing, directly satisfying the requirement.

  • ✗

    Add comments describing what should happen if the file is missing

    Why it's wrong here

    Comments are ignored by the compiler or interpreter and have no effect at runtime. Documenting the intended behavior does not prevent the exception or display any message. The program would still terminate abruptly when the file is absent, so this approach does not solve the problem.

  • ✗

    Use a loop to retry the file read indefinitely until it succeeds

    Why it's wrong here

    An infinite retry loop would spin forever if the file never appears, consuming CPU and never showing the friendly message. It also ignores the instruction to inform the user. Without a termination condition or error handling, this approach is worse than doing nothing, so it is not appropriate.

  • ✗

    Declare the file path as a constant at the top of the program

    Why it's wrong here

    Declaring the path as a constant improves maintainability by avoiding repeated literals, but it does nothing to handle a missing file. The read operation still throws an exception when the path does not resolve to a file. Constants affect organization, not error handling, so they do not meet the stated requirement.

About these practice questions

One of 988 original FC0-U71 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 →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official CompTIA exam blueprint

This FC0-U71 practice question is part of Courseiva's free CompTIA 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 FC0-U71 exam.