next up previous
Next: Errors detected by the Up: Unit 09 Previous: Semantic errors

Logical errors

Logical errors are caused by the fact that the software specification is not respected. The program is compiled and executed without errors, but does not generate the requested result.

Let us see some examples of logical errors:

Example 1: Errors in the performed computation:

public static int sum(int a, int b) {
  return a - b ;
}
// this method returns the wrong value wrt the specification that requires
// to sum two integers

Example 2: Non termination:

String s = br.readLine();
while (s != null) {
  System.out.println(s);
}   // this loop does not terminate


next up previous
Next: Errors detected by the Up: Unit 09 Previous: Semantic errors