Meaning of Debugging
Debugging means the process of finding errors, finding reasons for errors, and techniques of their fixation. An error, also known as a bug, is a programming code that prevents a program interpretation.
Errors are of three types –
- Compile Time Error
- Run Time Error
- Logical Error
Compile-time error :
These errors are basically of 2 types –
Syntax Error: Violation of formal rules of a programming language results in a syntax error.
For ex-
a=5
if a>10
SyntaxError: ‘:’ syntax error
Semantics Error: Semantics refers to the set of rules which sets the meaning of statements. A meaningless statement results in semantics error.
For ex-
x * y = z
Logical Error
If a program is not showing any compile-time error or run time error but not producing desired output, it may be possible that the program is having a logical error. These are not detected by the compiler or interpreter. These are hard to detect.
Some example-
- Use a variable without an initial value.
- Provide wrong parameters to a function.
- Use of the wrong operator in place of correct operator required for operation.
X=a+b (here – was required in place of + as per requirement
Run time Error
These errors are generated during a program execution due to resource limitations. Python is having the provision of checkpoints to handle these errors.
For ex-
a=10
b=int(input(“enter a number”))
c=a/b
Value of b to be entered at run time and the user may enter 0 at run time, that may cause run time error because any number can’t be divided by 0
Run time Error in Python
In Python, try and except clauses are used to handle an exception/runtime error which is known as exception handling
try:
# code with a probability of exception will be written here.
a=10
b=int(input(“enter a number”))
c=a/b
except:
#code to handle exception will be written here.
print(“divide by zero error”)
[wpdatatable id=1]