Monday, June 6, 2016

Debugging and Error Handling

   This script contained a few syntax errors that prevented it from listing the field names in the attribute table of a shapefile.
    This script contained syntax errors, incorrect pathfile locations, incorrect methods, and I had to adjust the parameters of a method. It lists the layers found in this module's map document.
    This script incorporates a try/except statement to catch an exception, instead of fixing the errors. Catching an exception bypasses the error statement when trying to run the code and instead prints out  the main issue. The second part of the script runs successfully and lists the name of the data frame, the set spatial reference of the map document, and the scale of the map document.
   This flowchart shows the process of the second script (second screenshot).
   This is how I incorporated a try/except statement into the third script:
1.      I added ‘try:’ to the top of the code, highlighted the rest and tabbed it.
2.      I added ‘except Exception as exc:         print “An error has occurred.”            Print exc          to the bottom of the code as shown in the mod 4 lecture.
3.      I only did this for Part A, as the directions for Part B said it would run successfully.

No comments:

Post a Comment