Types of errors and debugging in programming

Image is used from Google for representational purpose only

Before we dive into debugging and the types of errors aka bugs in a computer program, first we will see what actually a bug is.

Have you heard of errors (bugs) in programming?

While programming every programmer with good intentions will try to write a program which can run as expected without any errors. But, in this process of creating a bug-free (error free) programs, we unintentionally introduce bugs into the program.

There is no program which is bug free all the time. A program may be bug free at the time it was written but as the user base increases at some point of time in the future that bug free program will have bugs in it.

That is the main reason why programmers will be anticipating future errors and will be improving their programs from time to time.

Types of errors in programming

  • Syntax errors
  • Run time errors
  • Semantic errors

Syntax Errors

Your programming language’s compiler / interpreter will tell you where the syntax error is in the program along with the file name and the number. These are the easiest to be found.

Below is a gist to demonstrate what a syntax error is. In the gist, on line number 7, you can see that there is no semicolon.

When you try to run this program, you will be shown an error Parse error: syntax error, unexpected ‘echo’ in filename on line 10

Runtime Errors

As shown in the below gist, you can see that there is no syntax error in it. But, when you try to run this program you will be shown an error saying that Undefined variable: var_2 along with the filename and line number

Semantic Errors

It is an error which is present in the logic of your program.

As shown in the below gist, you can see that there is no syntax error in it and when you try to execute it, the program will also execute successfully. But, the result is not the one which you might be expecting.

In the gist, as mentioned in the comments, the program should return the sum of other two variables, but the program is actually returning the difference of the two variables.

What is Debugging?

How to debug your program?

Now a days, there are debugger tools and extensions available for developers which will help you in debugging and make your life easy.

You can keep check points, turn on the debugger and then execute the program to check whether the data passed in your program from one part to another part is same as you are expecting.

IDEs (Integrated Development Environment) like VS Code (Visual Studio Code) will come with inbuilt debugger extension, which is Node.js debugger extension. You can install other debugger extensions for different languages and can configure the debugger according to your needs.

#reacting to the challenges faced by users and developing solutions with the help of #php, #node, #mysql so that users can #vue the applications as intended