TYPES OF ERRORS IN PROGRAMMING LANGUAGE.
Tags: programming, computerscience, errors, devlopment
Published: 2023-02-25 18:17:31

😎🙌Greetings! 😎😎✨ As we delve into the realm of coding🐱‍🐉🐱‍🚀, we often encounter a variety of errors👀🤦‍♂️, be it in our personal projects or in the corporate world. Even as beginners, it is essential for us to foster our curiosity about these common errors that we encounter on a daily basis, in order to gain a deeper understanding of programming skills.

Well, there are several errors😢😢 you might face while coding. Still, I would like to share **4** common types of error which are generally encountered by us & should be well known by a programmer & a newbie in-order to debug it quickly to produce more effective & efficient code😃😃.

I'm going to break down these 4 errors in straightforward steps by providing a clear & simple explanation😎🙌 with a small code snippet for reference purposes.

1. **COMPILATION ERROR** -> Compilation errors generally occur due to mistakes in the "syntax" of the programming language.

When the programmer by mistake has left the semicolon (;) or has mistyped any keyword which is not accepted by the grammar(rules) of that specific programming language, we term it as a compilation error. It is relatively easy to fix.

We can also call it "syntax error" in simple words.



![Image description] (https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7ild3w3oz98kcbgk5w9.PNG)

Here, the programmer has mistyped the "println" keyword to "printnl" which is against the grammar(rules) of the programming language (here, I'm using JAVA), which will give the output.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8w8jmy3ltwx3409yfxy.PNG)

Here, the compiler throws the "compilation(syntax) error".
It can be fixed simply by changing the keyword to "println".



2.**RUN-TIME ERROR** -> Run-time errors are some of the exceptional types of errors where your code tries to perform or access such operations which are not allowed by the programming language.
The best examples are:

                   - Dividing a number by zero (0), which will 
                     simply throw, "ArithmeticException".


                     
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arkh29tuvt4r4l027yr9.PNG)

                   - Accessing a memory location that is not 
                     allocated, which will 
                     simply throw, 
                     "ArrayIndexOutOfBoundsException".


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gxpobyogukz4gluc5ruc.PNG)

Here, the compiler throws the "run-time error".


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/parw63tca8wwbwuvq1rt.PNG)

It can be fixed simply by accessing the location that is under the scope of an array.

                  - Invalid input in Java can cause a runtime 
                    error when the program is expecting certain 
                    types of input, but the input provided by the 
                    user is not valid. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12b5n4b6pjpjwavgyy6u.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i7o7hlr5iqecmisdo6h1.PNG)


3.**TIME-LIMIT EXCEEDED** -> This error is generally thrown by the compiler when your code runs or executes an infinite number of times (goes into an infinite loop). The program will never finish its execution, eventually encountering a "Time Limit Exceeded" error. 

We can fix it by adding a counter variable that counts the number of iterations and exits the loop when it reaches a particular value (say 10), You can also use a condition that depends on the programmer's input.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufpjb9kei2lv2rnh0gbj.PNG)

It will throw the "Time Limit Exceeded" error. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ja03hlheopn76t0uodyr.PNG)



4.**SEGMENTATION FAULT **-> This error occurs when your code tries to access memory that it is not allowed to access by it.
The segmentation error is also one of the runtime errors, so what's the difference peeps👀😒?

In simple words😃 a segmentation fault is a specific type of runtime error that occurs when a program tries to access memory it is not allowed to access, while a runtime error is a more general term that encompasses a wide range of errors that can occur during program execution like - division by zero, array out-of-bounds access. 

A segmentation fault will lead to a crash of your program in most cases🤷‍♂️🤷‍♂️ (logs of this fault(error) are recorded in the file named "CORE DUMPS" with an extension- .dmp extension).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iowq7xkpl5p8fsj4fj71.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gloubxlyxmrfvbhlhr31.PNG)


I hope😎🙌 this post helps the budding developer community & newbies who want to delve into errors in their code & saves their time by spotting them easily.😃💖✨😎

Thank You!!!