Sei sulla pagina 1di 19

Program Troubleshooting

Table of Contents

iii

Table of Contents
Table of Contents ..................................................................................................... iii
Introduction ................................................................................................................v
Syntax Errors..............................................................................................................3
Error: .......................................................................................................................3
Fix: ..........................................................................................................................3
Semantic Errors ..........................................................................................................7
Error: .......................................................................................................................7
Fix: ..........................................................................................................................8
Run-time Errors........................................................................................................11
Error: .....................................................................................................................11
Fix: ........................................................................................................................11
Index .........................................................................................................................13

Introduction

Introduction
This manual was designed for students enrolled in CSCE 1030. This manuals
purpose is to help students troubleshoot their own programs and serve as a
reference guide to help find and fix errors in the users code. This manual contains
material for the three types of errors, and solutions for fixing such errors.

Syntax Errors

Syntax Errors
Error:
Syntax errors are violations in the syntactic rules of a programming language.
The compiler will identify the syntax error by giving the errors location and type
of error.
When you first start programming, a couple common syntax errors include:

Not ending a line with a semicolon.


Using commas in for-loop arguments instead of semicolons.
Mistyping variable names.
Misusing functions.

Fix:
First find the location of the error. When you try to compile your code the compiler
will give you the line number in the error. Return to your code and go to that line
and scan for an error in your code with the type given by the compiler.

Semantic Errors

Semantic Errors
Error:
Semantic errors are logical mistakes in your code.
These are tricky to catch at first because they will compile correctly and run
correctly but will result in wrong results.
When you first start programming, a couple common semantic errors include:
Getting wrong input due to garbage in your buffer.
o This problem occurs a lot while trying to scan for strings.
o If you have scanned for any other variable before a string you must
clear the buffer to ensure you are getting the information you want.
Incorrect use of incrementing/decrementing before/after you wanted it.
Incorrect variable interactions.

Program Troubleshooting

Fix:
Finding the error is the only way to start fixing this. The best way to find a
semantic error is by printing out different instances of your variables. That is, to
print out your variables at different times (before and after every time they are
changed) until you find out what you have wrong. Once you find where the
problem occurs it is usually easy enough to fix the problem.

Run-time Errors

11

Run-time Errors
Error:
Run-time errors occur during program execution. Also tricky to find because the
compiler does not warn you and usually the program will crash without giving
much help as to why it happened.
When you first start programming, a couple common run-time errors include:
Invalid data entry into variables.
Attempting to use memory that has not been allocated to your program.
Dividing a number by 0.

Fix:
The best way to fix these errors depends on what you are using.
When scanning for information, make sure the correct data type is entered and
have fail safes to clear the buffer if an incorrect data type is entered.
If you are using an array, check and make sure that youre not using an index of
the array that is not part of the array.
If you are using division (by a variable) make sure the variable cannot and does not
equal 0 when youre dividing.

Index

13

Index
allocated, 11
buffer, 7
compiler, 3
data type, 11
for-loop, 3
functions, 3
garbage, 7
incrementing/decrementing, 7
logical mistakes, 7

memory, 11
program execution, 11
programming language, 3
Run-time errors, 11
Semantic errors, 7
syntactic rules, 3
Syntax errors, 3
variable, 3
violations, 3

Potrebbero piacerti anche