Module 3 - Debug & Error Handling

This week we focused on how to debug and handle errors. This was quite beneficial as this section was not taught to us way back in college. I think it's important to learn this on how we can proper debug and handle errors as we experience this a lot when coding - whether it's python or other programming language. Discussing this an an early stage will help us avoid mistakes or if we do have mistakes we know how to find and fix them.

It is important to note that:
  • Be aware of indentation especially when using try-except, if-else, for-while, etc. This is very crucial in your program code.
  • The most common mistakes we have is we forget to be mindful of (1) punctuation (e.g. colons in after the statements mentioned above), (2) capitalization - make sure that you're using the right letter case when you define a variable and calling it out, (3) spelling
  • It is essential to make use of Spyder's debugger tool that can help you review line by line on where you're experiencing an error.
  • And most importantly, comment like crazy as this will help you to remember what each line does and figuring out if there are any mistakes in the line.

Script 1
It is pretty straight forward as it only required a syntax correction, spell checks, punctuataion checks and path name fix. Here's a flowchart after it has ran successfully and screenshot of results on IPython Pane after errors have been fixed.





Script 2
In here, I'm not sure if made a mistake of counting how many errors I changed but I only counted 6/7 mistakes and still it returned the right results. I had to go over it again and still I was only able to find around that number. It's also just a combination of syntax errors, file path names (using non-existing project change that to the correct file path), and logical errors. I did use the debugger tool in here just to make sure but I guess my counting was wrong. Here's a flowchart after it has ran successfully and screenshot of results on IPython Pane after errors have been fixed.




Script 3
Lastly, we had a script having as more involved by using a try-except statement. The try-except statement will help us define the error neatly and run the code with error exceptions. If your codes are divided into parts then this is helpful so that you know which parts are producing an error. I honestly did overthink this section as the solution was actually simple like in the given example in the assignment document (except e, print e). I ran the file first to know what error exception should I call out and add to the except block. Part A was the only one that has an error because there are no parks layer and then Part B works fine. But without the try-except statement then Part B won't run until that error is fixed.Here's a flowchart dividing Part A and B, where only A had the try-except statement since B is working fine. Also, a screenshot of results on IPython Pane after try-except block was used to override the error (for the meantime).





Comments

Popular posts from this blog

M1 S4 - Suitability Analysis / Least Cost Path

GIS Portfolio

Module 4 - Geoprocessing