nerdexam
CompTIA

PT0-003 · Question #268

A penetration tester creates the following Python script that can be used to enumerate information about email accounts on a target mail server: Which of the following logic constructs would permit…

The correct answer is C. Add a try/except block. Try/Except: Handling Failures Gracefully A try/except block is the correct answer because it is specifically designed to catch and handle runtime errors (exceptions) without crashing the program - allowing the script to continue enumerating other email accounts even if one…

Submitted by yasin.bd· Mar 6, 2026Reconnaissance and enumeration

Question

A penetration tester creates the following Python script that can be used to enumerate information about email accounts on a target mail server:

Which of the following logic constructs would permit the script to continue despite failure?

Exhibit

PT0-003 question #268 exhibit

Options

  • AAdd a do/while loop.
  • BAdd an iterator.
  • CAdd a try/except block.
  • DAdd an conditional.

How the community answered

(33 responses)
  • A
    6% (2)
  • B
    3% (1)
  • C
    82% (27)
  • D
    9% (3)

Explanation

Try/Except: Handling Failures Gracefully

A try/except block is the correct answer because it is specifically designed to catch and handle runtime errors (exceptions) without crashing the program - allowing the script to continue enumerating other email accounts even if one attempt fails (e.g., a connection timeout or invalid account). This is essential in penetration testing scripts where individual failures are expected and should not halt the entire enumeration process.

Why the distractors are wrong:

  • A (do/while loop): A loop controls repetition of code, but does not handle errors - an unhandled exception will still crash the script regardless of the loop structure.
  • B (Iterator): An iterator is used to traverse collections of data sequentially; it has no built-in mechanism for catching or suppressing errors.
  • D (Conditional): An if/else conditional can check for anticipated conditions, but cannot catch unexpected runtime exceptions that would otherwise terminate execution.

Memory Tip: Think "TRY to do the task, EXCEPT when something goes wrong - keep going!" Whenever a question asks about continuing despite failure or handling errors gracefully, that's your signal to choose try/except.

Topics

#Python scripting#Error handling#Script resilience#Enumeration tools

Community Discussion

No community discussion yet for this question.

Full PT0-003 Practice