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…
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
Options
- AAdd a do/while loop.
- BAdd an iterator.
- CAdd a try/except block.
- DAdd an conditional.
How the community answered
(33 responses)- A6% (2)
- B3% (1)
- C82% (27)
- D9% (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/elseconditional 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
Community Discussion
No community discussion yet for this question.
