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")
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
}
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))
Name Error:
Python cannot find a variable, function, or identifier that is being referenced in the program.
Example:
age = 25
print(user_age)
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())

Top comments (0)