๐๐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.
- 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.
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.
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".
- Accessing a memory location that is not
allocated, which will
simply throw,
"ArrayIndexOutOfBoundsException".
Here, the compiler throws the "run-time error".
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.
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.
It will throw the "Time Limit Exceeded" error.
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).
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)