4. Debugging
Identifying and Correcting Errors
• Debugging is the process of
fi
nding and correcting existing and
potential errors (also called bugs) in software code.
• Bugs can cause software code to behave unexpectedly or crash.
Grace Hopper
7. Syntax errors
Identifying and Correcting Errors
• These are errors that occur when you have not followed the rules of the language, and they
will be
fl
agged by the translator.
• A program with syntax errors will not run.
• Common causes of syntax errors:
• Spelling or typing errors
• Missing parentheses, ( ) or { }, ; in statements in which they are required by the
language.
• Missing or unexpected indentation in Python
• Printing a value without declaring it.
9. Logic errors
Identifying and Correcting Errors
• Errors that cause a program to work incorrectly or unexpectedly.
• With a logic error, the program can be run without failing, but it does not return the
expected result.
• Common causes of logic errors
• Not correctly understanding what the program needed to do.
• Using the incorrect logical operator in a selection statement.
• Missing or incorrect positioning of brackets in mathematical calculations, which means
that the incorrect result is returned.
• Loops that execute more or fewer times than intended.
11. Runtime errors
Identifying and Correcting Errors
• Errors occur when the program is run. They are sometimes also referred to as execution errors.
• When the code is valid according to rules of syntax and semantics, and is also logically correct,
but the environment that the program is being run in or the input provided causes an error to
occur.
• Coming causes of runtime errors:
• Trying to access a list item that does not exist.
• A mathematical calculation that results in the program trying to divide by 0.
• Trying to perform numerical operations on strings.
• Linking to a
fi
le or resource that has been moved or longer exists.
13. Semantic errors
Identifying and Correcting Errors
•Errors occur where there is improper use
of a program code statement, and they
are
fl
agged by the translator.
14. Identifying and Correcting Errors
Creative Development
• A logic error is a mistake in the algorithm or program that causes it to behave
incorrectly or unexpectedly.
• A syntax error is a mistake in the program when the rules of the
programming language are not followed.
• A run-time error is a mistake in the program that occurs during the execution
of a program. Programming languages de
fi
ne their own run-time errors.
• An over
fl
ow error is an error that occurs when a computer attempts to
handle a number that is outside of the de
fi
ned range of values.
15. Learning Objective:
Identify inputs and corresponding expected
outputs or behaviors that can be used to check
the correctness of an algorithm or program.
16. Identifying and Correcting Errors
Creative Development
• In the development processes, testing uses de
fi
ned inputs to ensure that an
algorithm or program is producing the expected outcomes.
• Programmers use the results from testing to revise their algorithms or
programs.
• De
fi
ned inputs used to test a program should demonstrates the di
ff
erent
expected outcomes that are at or just beyond the extremes (minimum and
maximum) of input data.
• Program requirements are needed to identify appropriate de
fi
ned inputs
for testing.
17. Identifying and Correcting Errors
Creative Development
• The following are e
ff
ective ways to
fi
nd and correct errors:
• Test cases
• Hand tracing
• Visualization
• Debuggers
• Adding extra output statement(s)
18. We should know…
Identifying and Correcting Errors
• Before a piece of software can be used, it needs to be tested.
• Other testing is more structured and involves a test plan.
• When a problem with the software is identi
fi
ed, the cause will need
to be identi
fi
ed. This is called debugging.
20. Things to ponder…
Identifying and Correcting Errors
•Give at least three (3) examples of
errors might occurs during creating a
code blocks.
21. Identifying and Correcting Errors
Creative Development
• A logic error is a mistake in the algorithm or program that causes it to behave
incorrectly or unexpectedly.
• A syntax error is a mistake in the program when the rules of the
programming language are not followed.
• A run-time error is a mistake in the program that occurs during the execution
of a program. Programming languages de
fi
ne their own run-time errors.
• An over
fl
ow error is an error that occurs when a computer attempts to
handle a number that is outside of the de
fi
ned range of values.
23. Identifying and Correcting Errors
Creative Development
• The following are e
ff
ective ways to
fi
nd and correct errors:
• Test cases
• Hand tracing
• Visualization
• Debuggers
• Adding extra output statement(s)