编程中的错误类型

The programmer should know the fact that there is very less
chances that a program will run perfectly in first time. It doesn’t matter how
nicely the designing is done and how much care is taken while coding. One can’t
say that the program would 100% error free. So the programmer has to make
efforts to detect and rectify any kind of errors that are present in the
program. But before detecting and removing errors it is much more necessary
that the programmer should know about the types of errors in programming. This article will
explain you about the types of errors in programming that must be taken care while writing
your program.

Types of Errors in Programming

The types of errors are classified into four categories.
These are: syntax errors, logical errors, run-time errors and latent errors.
Syntax Errors
Any violation of rules and poor understanding of the
programming language results in syntax errors. The compiler can detect such
errors. If syntax errors are present in the program then the compilation of the
program fails and is terminated after showing the list of errors and the line
number where the errors have occurred. In some cases the line number may not
exactly indicate the correct place of the error. In some other cases, a single
syntax error can result in a long list of errors. Correction of one or two
errors in the program may remove the entire list of errors.
Run-time Errors
Runtime errors are the errors that occur during the
execution of the program. Some examples are, dividing by zero error,
insufficient memory for dynamic memory allocation, referencing an out-of-range
array element. These are not detected by compiler while compilation process. A
program with these kinds of errors will run but produce erroneous results or may
cause termination of program. Detection and removal of a run-time error is a
difficult task.
Logical Errors
As the name itself implies, these errors are related to the
logic of the program. Logical errors are also not detected by compiler and
cause incorrect results. These errors occur due to incorrect translation of
algorithm into the program, poor understanding of the problem and a lack of
clarity of hierarchy of operators. Consider following C statement:
if(a==b)
                printf(“Equaln”);
When a and b are float types values, they rarely become
equal due to truncation errors. The printf call may not be executed at all. A statement
like while(a!=b) might create an infinite loop.
Latent Errors
Latent Errors are the ‘hidden’ errors that occur only when a
particular set of data is used. Consider below example:
result = (a+b)/(c-d);
An error occurs only when c and d are equal because that
will make remainder zero (divide by zero error). Such errors can be detected
only by using all possible combinations of data.
The programmer should know the fact that there is very less
chances that a program will run perfectly in first time. It doesn’t matter how
nicely the designing is done and how much care is taken while coding. One can’t
say that the program would 100% error free. So the programmer has to make
efforts to detect and rectify any kind of errors that are present in the
program. But before detecting and removing errors it is much more necessary
that the programmer should know about the types of errors in programming . This article will
explain you about the types of errors in programming that must be taken care while writing
your program.

Types of Errors in Programming

The types of errors are classified into four categories.
These are: syntax errors, logical errors, run-time errors and latent errors.
Syntax Errors
Any violation of rules and poor understanding of the
programming language results in syntax errors. The compiler can detect such
errors. If syntax errors are present in the program then the compilation of the
program fails and is terminated after showing the list of errors and the line
number where the errors have occurred. In some cases the line number may not
exactly indicate the correct place of the error. In some other cases, a single
syntax error can result in a long list of errors. Correction of one or two
errors in the program may remove the entire list of errors.
Run-time Errors
Runtime errors are the errors that occur during the
execution of the program. Some examples are, dividing by zero error,
insufficient memory for dynamic memory allocation, referencing an out-of-range
array element. These are not detected by compiler while compilation process. A
program with these kinds of errors will run but produce erroneous results or may
cause termination of program. Detection and removal of a run-time error is a
difficult task.
Logical Errors
As the name itself implies, these errors are related to the
logic of the program. Logical errors are also not detected by compiler and
cause incorrect results. These errors occur due to incorrect translation of
algorithm into the program, poor understanding of the problem and a lack of
clarity of hierarchy of operators. Consider following C statement:
if(a==b)
                printf(“Equaln”);
When a and b are float types values, they rarely become
equal due to truncation errors. The printf call may not be executed at all. A statement
like while(a!=b) might create an infinite loop.
Latent Errors
Latent Errors are the ‘hidden’ errors that occur only when a
particular set of data is used. Consider below example:
result = (a+b)/(c-d);
An error occurs only when c and d are equal because that
will make remainder zero (divide by zero error). Such errors can be detected
only by using all possible combinations of data.

翻译自: https://www.thecrazyprogrammer.com/2014/08/types-of-errors-in-programming.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值