hardMultiple Select
Python Error Handling for Network Automation - Cisco ENCOR 350-401
Which three statements about error handling and debugging in Python network automation scripts are true? (Choose three.)
Quick Answer
The correct answers are B, C, and D, as they represent the three essential techniques for robust Python error handling in network automation. Try-except blocks allow scripts to catch and manage exceptions like connection timeouts or authentication failures without crashing, while logging provides a structured, timestamped record of events for post-mortem analysis. Print statements, though simple, are invaluable for debugging variable values during development by outputting state information directly to the console. On the ENCOR 350-401 exam, this topic tests your ability to distinguish between production-ready error handling and development-only debugging tools; a common trap is confusing the `pass` statement—which silently swallows errors—with a valid handling strategy, or thinking `continue` belongs in error handling when it actually controls loop flow. Remember the mnemonic “Try, Log, Print” to recall the three correct techniques, and always avoid `pass` in production code.
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
✓
The try-except block allows a script to handle connection timeouts without crashing.
Option B is correct because wrapping network calls (e.g., socket.connect or requests.get) in a try-except block lets the script catch exceptions like socket.timeout or TimeoutError and handle them gracefully instead of terminating. Option C is correct because Python's logging module provides configurable handlers such as FileHandler and RotatingFileHandler to persist error and debug messages to a file, which is essential for auditing automation runs. Option D is correct because print() statements are a common, simple debugging technique during development to inspect variable values and trace execution flow before formal logging is added. Option A is not correct because using 'pass' in an except block silently swallows exceptions, hiding failures and making production troubleshooting difficult; best practice is to log or re-raise. Option E is not correct because 'continue' is a loop control statement that skips to the next iteration, not an exception-handling mechanism; exceptions are handled with try-except-finally.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Using 'pass' in an except block is a best practice to ignore errors in production scripts.
Why it's wrong here
A bare pass in an except block silently swallows the exception, hiding failures and leaving faults undiagnosed in production. It is tempting as a quick way to stop a script crashing, but pass is for intentionally empty blocks such as placeholder functions or classes, not for suppressing genuine runtime errors that need logging or remediation.
- ✓
The try-except block allows a script to handle connection timeouts without crashing.
Why this is correct
Wrapping connection attempts in try-except lets the script catch socket timeouts and similar exceptions, then log or retry rather than terminating abruptly. This directly satisfies the stem's requirement that a script handle connection timeouts without crashing.
- ✓
Using the logging module helps record errors and debug information to a file.
Why this is correct
The logging module writes timestamped, levelled messages to files or handlers, so errors and debug detail persist after the script exits. This satisfies the requirement to record diagnostic information for later review rather than losing it to the console.
- ✓
Print statements can be used to debug variable values during script development.
Why this is correct
Print statements output variable values at chosen points during execution, letting developers inspect state and trace faulty logic interactively. This satisfies the debugging requirement during script development, though such statements are typically removed before production.
- ✗
The continue statement is used to handle exceptions in Python.
Why it's wrong here
The continue statement skips the remaining code in the current loop iteration and proceeds to the next; it has no exception-handling role, which try/except/finally provide. It is tempting because loop control and error recovery often appear together in scripts, but continue belongs in iteration logic, not in catching or handling raised exceptions.
Go deeper
Related to this question
Learn chapter
Network Monitoring and Troubleshooting Tools
Key term
Cisco DNA Center Automation
Cisco DNA Center Automation is a centralized software platform that simplifies network management by automatically configuring, monitoring, and troubleshooting Cisco devices using policy-driven intent and software tools.
About these practice questions
One of 1,923 original 350-401 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 →
Same concept, more angles
1 more way this is tested on 350-401
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A network engineer is writing a Python script to automate the backup of running configurations from a list of 50 Cisco IOS-XE devices. The script uses the netmiko library and a for loop to connect to each device, execute 'show run', and write the output to a file. After running the script, the engineer notices that the script fails on the 15th device with a timeout error, and the remaining devices are not processed. The engineer wants to ensure that if one device fails, the script continues with the next device. What is the best way to modify the script?
medium- A.Increase the global timeout value in the netmiko connection handler.
- B.Use the concurrent.futures module to run each connection in a separate thread.
- ✓ C.Wrap the connection and backup logic inside a try-except block within the for loop.
- D.Replace the for loop with a while loop that retries the connection three times before moving on.
Why C: Wrapping the connection and backup logic inside a try-except block within the for loop catches exceptions (such as netmiko's NetMikoTimeoutException) for each device individually. This allows the loop to continue processing the remaining devices after a failure, rather than aborting the entire script. The try-except pattern is the standard Python approach for handling runtime errors without breaking iterative processes.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 350-401 practice question is part of Courseiva's free Cisco 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 350-401 exam.