Module 3 of Computer Programming for GIS introduced us to the various types of errors that can occur during coding, ranging from basic syntax errors to more complex runtime errors.
A syntax error is a mistake in the script, such as missing punctuation, misspellings, or incorrect letter casing. This type of error prevents the program from running altogether because the interpreter cannot understand the code. In contrast, a runtime error occurs during script execution and can cause the program to terminate unexpectedly unless error handling is implemented. Examples of runtime errors include division by zero, attempting to access an undefined variable, or referencing an incorrect file path.
We explored the debugging process for our scripts, learning about various methods and tools to assist us. Additionally, we discussed error handling, which involves writing code to define how the program should respond when an error occurs, particularly through the use of try-except statements. This allows the program to manage errors without crashing, enabling the execution of the subsequent code.
Our Module 3 lab assignment included three scripts for us to work on.
In Script 1, we focused on identifying and correcting simple syntax errors, primarily involving misspellings and inconsistencies in letter casing (since Python is case-sensitive).
Script 2 presented a greater challenge with several errors to identify and fix. This script contained both syntax and runtime errors, including an incorrect file path. I was pleased to recognize and correct most of the errors before my initial attempt to run the script. The final error I encountered stemmed from having the project file open in ArcGIS Pro, which prevented the program from modifying the .aprx file. Once I closed ArcGIS Pro, the script executed as intended.
Script 3 was the most advanced part of this module, requiring us to implement error handling (try-except) for a known error in the code. Pictured below is the flowchart I created illustrating the process.
Overall, this was a fun and informative module, and I genuinely enjoyed it. I can see how debugging a large program could be tedious and time-consuming, but I'm optimistic about refining my skills to navigate the process efficiently and effectively.