1.4 Identifying and Correcting Errors

15 阅读1分钟

1. Exam Points

  • Understand different types of errors:
    • Syntax error : Ex. in a = 10;
    • Run-time error : Ex. 10/0
    • Logic error : occurs when an algorithm generates a result that is not expected.
    • Overflow error: occurs when tryig to store a value out of the range of a data type.
  • Identify and Correct errors (logic errors) in a code segment or procedure.

2. Knowledge Points

  • (1) Error

    • An error is a condition that interrupts the normal execution of a program.
    • Types of error:
      • Syntax error : is a mistake in a program where the rules/syntax of the programming language are not followed.
      • Run-time error : is a mistake in the program that occurs during the execution of a program. Programming languages define their own runtime errors.
      • Logic error : is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly.
      • Overflow error : is an error that occurs when a computer attempts to handle a number that is outside of the defined range of values.
  • (2) Correct the error

    • The following are effective ways to find and correct errors:
      • test cases
      • hand tracing
      • visualizations
      • debuggers (breakpoint)
      • adding extra output statement(s)

3. Exercises