Handling Debugging in Python

 This week has left me feeling much more confident in my ability to code. We learned about common error messages and how to handle them through a process called debugging. We were given three pre-made scripts and were tasked with finding and debugging the errors. 

The first script included simple syntax errors, which are errors in the convention of the coding language. These commonly include misspellings, incorrect upper or lowercase usage, missing punctuation, or incorrect indentation. Below is a screenshot of the script output after correcting for syntax.



The next script was much more challenging. There were multiple syntax errors but, after these were corrected, the script returned with an exception error. Exception errors occur when the script is able to run correctly but something "unexpected" happens. These can be caused by empty feature classes, incorrect work environments, or strange user input.


Exception errors can be "trapped" with try-except statements. As seen in the flowchart below, we can write the code in such as way to go around the exception. 


We can even have the exception error message printed along with the rest of the desired results. 





Comments

Popular posts from this blog

Coastal Flooding & Storm Surge Analysis

Welcome to GIS 5007 Spring 2023

Introduction to Python