DEV Community

Cover image for TYPES OF ERRORS IN PROGRAMMING LANGUAGE.
Rahul Pratap Singh
Rahul Pratap Singh

Posted on

TYPES OF ERRORS IN PROGRAMMING LANGUAGE.

๐Ÿ˜Ž๐Ÿ™Œ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

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

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".
Enter fullscreen mode Exit fullscreen mode

Image description

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

Image description

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

Image description

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. 
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

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

It will throw the "Time Limit Exceeded" error.

Image description

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

Image description

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!!!

Top comments (0)