Tuesday, June 7, 2016

Debugging and Error Handling

GIS Programming - Mod 4

Debugging and error handling are crucial aspects of programming.  Mistakes happen and when then do it's very important to know how to fix them.  Our assignment this week was to work on three scripts that had errors in them.  The first script was to print out the names of all the fields in an attribute table of a shape file.  It had a couple typos that needed to be fixed, then ran fine.

Script 1 Results


The second script was to print out the names of all the layers in the data frame in a map.  This one was a little more complex.  In this script we had to correct 8 errors of different types, from correcting paths, to typos, to adding or removing arguments from statements.

Script 2 Results

The last script was the most difficult in that it was a difficult concept to understand.  The intent of the script was to return an error statement for Part A and certain information from the data frame of a map for Part B.  Part B had no errors in it, but we had to get through Part A before we could get there.  Instead of correcting the errors in Part A we had to use a try-except statement to allow the script to run through the error portion without failing, but returning a relevant error message, then move on to the second portion of the script.  To accomplish this I ran the script to see where my first error was then investigated that.  I saw I was missing an argument in a statement so I placed my try before that line.   At this point I wasn’t really sure how the try-except worked so tried the except after the for statement to see what that would do.  I ran the script again and came up with another error.   I realized at this point that nothing after setting mapdoc could work right because everything was based off mapdoc being correct so I moved my except to the end of Part A and added the second error type to the argument and ran the script.  This time my script ran correctly, but I realized by moving the except where I did I shouldn’t be getting that second error any more so I removed that and tried again and it was good.

Script 3 Results

We also had to do a flow chart for one of the scripts.  I chose to do it for Script 1.

Flow Chart of Script 1



No comments:

Post a Comment