hardMultiple SelectObjective-mapped
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.
Correct answers: B, C, and D. B is correct because try-except blocks allow the script to handle exceptions gracefully without crashing. C is correct because logging provides a structured way to record events and errors for later analysis. D is correct because print statements are a simple debugging technique to output variable values during development. A is incorrect because 'pass' is a no-op statement that silently ignores exceptions, which is not recommended for production code. E is incorrect because the continue statement is used in loops to skip to the next iteration, not for error handling.
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
Incorrect because using 'pass' silently swallows exceptions, making debugging difficult; it is better to log or handle errors appropriately.
- ✓
The try-except block allows a script to handle connection timeouts without crashing.
Why this is correct
Correct because try-except catches exceptions like timeouts, allowing the script to take alternative actions or retry.
- ✓
Using the logging module helps record errors and debug information to a file.
Why this is correct
Correct because the logging module provides configurable log levels and output destinations, which is essential for troubleshooting.
- ✓
Print statements can be used to debug variable values during script development.
Why this is correct
Correct because print statements are a simple and common way to inspect variable values and program flow during development.
- ✗
The continue statement is used to handle exceptions in Python.
Why it's wrong here
Incorrect because continue is used in loops to skip the current iteration; exception handling uses try-except blocks.
Go deeper
Related to this question
Learn chapter
Network Architecture Fundamentals
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,175 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.