Debugging and Error Handling




Debugging and Error Handling

GIS5103 - GIS Programming - Module 3


Learning outcomes:

Demonstrate the ability to fix syntax errors and exceptions
Implement debugging procedures
Modify scripts to run with exceptions
Interpret script error messages
Identify correct usage of try-except statements

This lab contained 3 scripts containing some of the most common types of errors and tested the knowledge of how Python works that we've learned thus far. This was our first application of the Try-Except statements covered in Chapter 7. This lab exposed us to several different types of error messages and gave us practice adding to scripts in order to make them run even when error codes are thrown. The 3 scripts used are described below:
Script 1:


This script prints out the name of all fields within an attribute table.


Script 2:


This script prints out all the names of all the layers present in a given file.


Script 3:


This script first turns on labels and visibility for layers in a given document and then prints the layer info. This required trapping several exception using try expect throughout the script. My process is demonstated below for the second half of this third script:


  1. First run script without making and changes to find a starting point.
  2. Use error code as a clue, examine code and try to find where this issue is originating.
  3. Inset try and except clause and try running again. Catch an further errors.
  4. When stuck go back to the basics and make sure the data is where you think it is, it has what you think it does in it (examine in arcGISpro), double check version of python.
  5. Try, fail, repeat.
  6. Review Textbook, look up you tube explanations, revisit exercises, to see if you can apply it to the problem in the lab.
  7. Guess right. Celebrate functional code with a snack break.
  8. Try to figure out why that worked.




Design a logical model of a script using a flowchart

Flow charts are an excellent way to visualize what your code is doing and how all the parts interact. It is also helpful when you're stumped on a problem.






Comments