GIS Programming: Debugging and Error Handling


"At the source of every error which is blamed on the computer you will find at least two human errors, 
including the error of blaming it on the computer."

~Anonymous



The art of debugging is arguably one of the most important skills for any programmer. Procedures for debugging include: 
  • Reviewing error messages 
  • Inserting print messages at select locations within the script
  • Commenting out lines or sections of code
  • Using a debugger 
Our task for this week's lab was to debug two pre-written scripts using some of the above procedures and add a try-except statement to a third script to catch the error. 


Script 1

Script one contained two errors and/or exceptions that needed to be fixed in order for the script to run. Once fixed, the script printed out the names of all fields within the parks.shp attribute table. 

Flowchart for Script 1.


Script 1 output. 


Script 2

Script 2 contained several errors/exceptions that needed to be corrected in order for the script to run. This script printed out the names of all the layers in the TravisCountyAustinTX.aprx project. 

Flowchart for Script 2.


Script 2 output. 


Script 3

Script 3 contained an error that prevented the script from running, but instead of fixing this error, our task was to insert a try-except statement so that the code would successfully run. 

Flowchart for Script 3.

 

Script 3 output.






Comments

Popular posts from this blog

Isarithmic Mapping: Annual Precipitation in Washington State

Spatial Enhancement, Multispectral Data, and Band Indices

Development Suitability Analysis