0% found this document useful (0 votes)
42 views20 pages

Lecture 4.3g Type of Error

This document discusses three types of programming errors: syntax errors which occur due to incorrect syntax and prevent compilation, run-time errors which cause abnormal program termination during execution due to invalid operations, and logic errors where the program executes without errors but does not perform as intended due to flawed logic. Debugging is the process of removing errors, and examples are provided for each error type along with how to identify them.

Uploaded by

brz2n6sm6b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views20 pages

Lecture 4.3g Type of Error

This document discusses three types of programming errors: syntax errors which occur due to incorrect syntax and prevent compilation, run-time errors which cause abnormal program termination during execution due to invalid operations, and logic errors where the program executes without errors but does not perform as intended due to flawed logic. Debugging is the process of removing errors, and examples are provided for each error type along with how to identify them.

Uploaded by

brz2n6sm6b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

4.

3
USE OF
CONTROL STRUCTURE

Programming
Learning Outcome

At the end of this topic, students should be able


to:

g) Explain types of programming errors:


• Syntax
• Run-time
• Logic
Programming
Programming Errors

• Programming error means an error which occurs during


the development of a computer program and when in
operation, result in a malfunction or incorrect operation
of a computer system.
• 3 types of programming errors:
– Syntax Error
– Run-time Error
– Logic Error
• Debugging is a process of removing errors from a
program.
Syntax
Syntax /
Compile-Time Error
• Indicate that there is something wrong with the
syntax of the program or
• Occurs when the syntax of the programming
language is violated.
• Common examples are:
– Misspelled variable and function names
– Missing semicolons
– Improperly matches parentheses, square brackets,
and curly braces
– Incorrect format in selection and loop statements
Syntax /
Compile-Time Error

• Example:
Syntax errors Corrected statements
integer number; int number;
double mark double mark;

• If syntax error detected, statement cannot be


translated and program cannot be executed.
Identify Syntax Error
Identify Syntax Error
3 Syntax Error detected!
Run-time
Run-Time Error

• Errors that cause a program to terminate abnormally.


• Occurs when program is running if the environment
detects an operation that is impossible to carry out.
• Occurs when a program with no syntax errors asks
the computer to do something that the computer is
unable to reliably do.
Run-Time Error

• Common examples are:


– Division by zero
(a=10/0;)
– Data-type error
(input with data type int but user enter symbol *)
– Perform operation on data of the wrong type
– A program stops and seem to be doing anything
(“hanging”)
Example of Run-Time Error
Example of Run-Time Error
Logic
Logic Error

• Occurs when a program does not perform the way it was


intended to.
• Common examples are:
– Multiplying when you should be dividing
– Displaying the wrong message
– Misuse logical operator
– Misuse relational operator
*Logic errors are hard to find because the compiler and interpreter
provide no information about what is wrong. Only programmer
know what the program is supposed to do and only programmer
know that it isn’t doing it.
Logic Error

• Very difficult to detect - it does not cause run-time


error and does not display error messages.
• The only sign of logic error is incorrect output
• Can be detected by testing the program thoroughly,
comparing its output to manually calculated results
Example of Logic Error

You might also like