Sunday, May 29, 2022

GIS 4102 - Module 2 - Debug/Error Handling

 For this weeks module 2 we were tasked with analyzing three provided scripts and troubleshooting them in order to locate and fix errors. Errors present themselves in python when the program compiler detects syntax errors that interfere with the script from running. The error message display indicates the syntax error that occurred. Checking for errors in python is relatively straightforward. Syntax can be quickly checked by looking at the code analysis on the left side of the code for error ! symbols. Syntax can also be quickly checked by running the script and observing the console results. Another final way syntax can be checked is by quickly running the debugger located on the spyder toolbar.

The first part of the assignment involved editing file-path and capitalization errors in script 1 in order to run a script that displays the names of  all fields  on  the  Module2/Data/parks.shp  attribute  table. Here is a screenshot of the spyder console successfully running the script.

The second part of the assignment also involved correcting file-paths, spelling errors, and functions. Once all errors were correct the script printed the names of all layers in the project file, TravisCountyAustinTX.aprx. Here is a screenshot of the spyder console successfully running the script.


The final part of the assignment involved successfully implementing a try-except statement. I added a try-except statement in the following places of the code in order to allow the script to run and print an error message. Adding the try statement to line 12 and the except statement to line 24 incorporated the bulk of the code where the error occurred. The except statement indicated the error message by print displaying the error statement, “The error is '__init__() missing 1 required positional argument: 'aprx_path''. After correcting another file-path error in part B the entire script was able to run error free. The result of the script displays the prints of part A indicating the try-except statement and the results of part B indicating name, data source, and the spatial reference of  each layer in the project file. Here is another screenshot of the spyder console successfully running parts A & B of the script.


No comments:

Post a Comment

Spring 2023 semester wrap up

 The spring 2023 semester at UWF has been an eventful one in which I finalized the requirements for my bachelors of science in natural scien...