DEV Community

Cover image for TYPES OF ERROR
Vinoth Kumar
Vinoth Kumar

Posted on

TYPES OF ERROR

TYPES OF ERROR IN PROGRAMMING:

We definitely come across some errors. It is very important for every programmer to be aware of such errors that occur while coding.

Syntax Error.
Logical Error.
Runtime Error.
Intentation Error.
Name Error.
TypeError.
Timelimit exceeded Error.(TBD)

Syntax Error:

When code violates the rules of the programming language such as missing semicolons, brackets, or wrong indentation of the code.

Example:

def syntax_error_example():
    if x == 5
        print("x is equal to 5")
Enter fullscreen mode Exit fullscreen mode

Logical Error:

When incorrect logic is implemented in the code and the code produces unexpected output.

Example:

float average(float a, float b)
{
    return a + b / 2;  // should be (a + b) / 2
}
Enter fullscreen mode Exit fullscreen mode

Runtime Error:

Errors caused by unexpected condition encountered while executing the code that prevents the code to compile. These can be null pointer references, array out-of-bound errors.

Intentation Error:

Python uses indentation (spaces or tabs) to define code blocks, even a small alignment mistake can prevent the program from running.

Example:

def check_number(a):
if a > 2:
    return "Greater than 2"

a = 5
print(check_number(a))
Enter fullscreen mode Exit fullscreen mode

Name Error:

Python cannot find a variable, function, or identifier that is being referenced in the program.

Example:

age = 25
print(user_age)
Enter fullscreen mode Exit fullscreen mode

TypeError:

operation or function is applied to an object of an inappropriate type, such as adding a string and an integer.

Example:

a = "GeeksforGeeks"
print(a())
Enter fullscreen mode Exit fullscreen mode

Top comments (0)