Milandeep Bassi

How to Debug and Handle Errors in Python Programming

23rd, January, 2020


Debugging

Errors in programming can be called "bugs" and the elimination of these errors is called debugging. There are 3 kinds of errors that can be found in a program. You can have Syntax errors, Run-time errors and Semantic errors. 


Syntax Errors

Python can only run if it's syntactically correct. If this is not the case it will return a syntax error. Syntax refers to to language in the program. If there is a syntax error, the python interpreter will return an error message and exit the program. 


Run-time Errors

These errors only appear while the program is actually running. They're also known as exceptions as they usually are the signs of an exception occurring. These errors lead the programme to usually crash and exit. 


Semantic Errors

A semantic error is when the program runs but the application does not do what you expected it to do. There will be no errors messages for this type of error. A semantic error means what you told the program to do is what it has done, however it was not what it was meant to do. These errors can be tricky to debug.


Debugging Technique

The first technique that you can use is to print() at important points in the program. By temporarily inserting a print() statement you can understand what is going on and see where the error comes from. This method of debugging is extremely useful with calculations. 


Programming Technique

When programming you can look at the task you have with a simple picture of Input-Process-Output. When creating an application first look at your inputs and the outputs that need to arrive from the inputs. Then you need to outline the steps to go from Input to output, aka the process.