Types of Errors while coding

Types of Errors while coding

Just like artists, writers, painter programmers are also too creative who had made our life so easy and comfortable.
But for programmers writing code in an efficient, effective, and exception free manner and also which fulfills user requirement is quite difficult. Every programmer one or the other time but most of them come across miscellaneous types of errors.
Even though mistakes our good and it builds experience but it’s sometimes stressful when an unexpected error comes across the way and passes you in your tracks. But by knowing the types of errors and a few common errors, will speedup the chance to resolve the issue easily.

Here are the four types of errors and few of the common errors that usually see in the way of coding.

1. Logical Errors: It is quite difficult to detect their types of errors because in this the program will run but the output will not as it is expected too.
Below are a few examples:
a. Creating a situation of an infinite loop.
b. In a calculation using incorrect brackets.
c. Null reference errors.
2. Syntax Errors: These occur when the written code doesn’t follow the syntactic rules define to write programs.
These are easier to detect and need to be corrected before the program run, these are detected at compile time.
Few examples of syntax errors are mentioned below:
a. The missing semicolon at the end of the line.
b. Or an extra bracket at the end of the function.
c. Using a variable before declaring it.
3. Runtime errors: These errors appear unexpectedly while the program is running. These errors are not known until occurred.
A runtime error crashes the program. Few examples of this type of error are mentioned below:
a. Accessing array index which is not present.
b. Division by zero.
4. Latent errors: These errors usually occur with a certain set of data. These may be because we programmers missed out on a few cases and scenarios.
Few of the examples are mentioned below:
a. In a case where you want to add values typed in two of the textboxes but if you accidentally missed out a case, where a user accidentally enters a text value.


Now as we have learned about various types of errors, let’s look at a few common errors that we usually face.
1. Object reference not set to an instance of an object
This is the common errors .Net beginner programmer face when you get a Null reference exception, we get this error message.
This exception is thrown at runtime when you access a member- for instance, a variable or property.
But before solving this what is the null reference?
What is reference first?
In .Net there are two categories of data types: value type and reference types.
If a variable is of value type then it stores the value itself but a reference type variable holds the reference of the object that is stored in the memory.
So null reference is a reference that doesn’t point to any object. When you try to call a member or a property of the null reference variable then you get this error. As you can see the below error message as shown in the image.
Object reference not set to an instance of an object
This occurs because LinkedList.head is a reference variable and there is no value assigned to it.
So, to avoid this type of exception at runtime handle this type of error by just checking the null value.
Object reference not set to an instance of an object
Object reference not set to an instance of an object
2. Division by zero
This is the mathematical error (not defined) occurs when we divide a number by zero.
As you can see the below error message as shown in the image.
division by zero
To not make your program to crash while running, handle this error, for this first check the divisor is zero if it is zero then return else divide the value. You can refer to the below image for handling.
division by zero
division by zero
3. The index was outside of bounds
This occurs when you are accessing an index value of array which is not present.
For eg; array size is 10 and you are accessing 11th index value

This occurred because of the loop is running till the length value but array value is positioned from o to length – 1 means in this the value are placed as

Position01234
value12345

By the above table, we are getting that there is no value at position zero, and values are placed from 0, not from 1.
So, the loop will run from zero to length – 1
Index was outside of bounds
Index was outside of bounds

Leave a Reply

Your email address will not be published.