Debugging Mayhem: One Error at a Time

 This week’s assignment was all about debugging and error handling—and let me just say, Python does not play around when something’s even slightly wrong. I worked through three different scripts, and each one had its own issues I had to fix or work around using try-except statements.


Script 1 was kind of a warm-up. I had to find two errors that were stopping it from printing the field names from a shapefile. Once I cleaned that up, the output showed all the fields like it was supposed to, and I snapped a screenshot of that to include here.


Script 2 was where things got slightly more annoying. I had to fix more errors and make sure the file paths were correct (which honestly took the most time). After that, the script finally printed the map’s spatial reference and a list of all the layers in the Austin, TX project.


Script 3 was all about using try-except. I had to intentionally leave one part broken and wrap it in a try-except so it wouldn’t crash the whole thing. Instead, it printed a custom error message and let the second part of the script run like normal. It printed each layer’s name, source, and spatial reference code. I included a screenshot showing that the error message popped up, but the rest of the script worked.



Here’s the flowchart I made for Script 3. It shows how the error is caught without stopping the rest of the code. Honestly, getting that part to work felt like a win.

                                                       

Overall, this module taught me how important it is to know exactly where your data is and how to read error messages without panicking. It also forced me to get more comfortable with debugging in general, which I know is going to come in handy for the rest of this class and anything else I do with Python.


Comments