Debugging different kinds of error The process of locating, identifying and correcting the errors in a piece of software is called debugging. Like many complex activities it is very unlikely that every program you write will work first time. There are two stages at which you will need to identify and attempt to debug (solve) errors in your programs: compile time it may not be possible for the compiler to understand your program, and so it will not be able to create a compiled bytecode object file run time even once a program has been successfully compiled errors may occur when you attempt to run the program
There are 2 types of error you will find at compile time: syntax errors errors in the form of a statement semantic errors syntactically correct statements which do not make sense in the language
The syntax of a language refers to the spelling, punctuation and grammar -- in other words whether a statement in the language follows the rules of the language. The English statement "Yestday me shops down went" contains both a spelling error " Yestday", and violations of English grammar, also this sentence should end with a full top -- a syntactically correct version of the sentence is "Yesterday I went down to the shops.". Syntax errors in programming languages such as Java include: spelling the names of reserved words wrong (for example writing "clas" instead of "class") forgetting required punctuation (in Java every statement should be followed by a semi-colon) putting punctuation in the wrong place not having matching pairs of parentheses "( )" or braces "{ }" and so on.
The semantics of a language refer to the meaning of the statements. An semantic error is an statement that meets a languages rules of syntax, but does not make sense. An English statement with a semantic error might be "Late one stone the angry table died." -- although the sequence of verbs and adjectives etc. are correct in this sentence, and the spelling and punctuation are correct, this sentence does not make sense, since a stone doesn’t have lateness, tables do not die or feel angry. Examples of semantic errors in Java include: trying to send a message to a variable that does not refer to an object trying to store some characters in a variable that can only stored integer values
The third kind of error you will encounter is the most difficult kind. You may get a program to successfully compile and run, but the program may not do what you intended. Errors in the way a program behaves are called logic errors. A logic error occurs when the computer can understand and execute your software, but the things it does are not what you intended. An example of a logic error in some instructions in English might be: "To drive to work, open your driver's door, sit in the drivers seat, start the engine, put the car into gear, drive along the route to work, park the car, switch off the engine, get out the car and close your driver's door". While following such instructions might get you to work, since you drove all the way without ever closing the driver's door the chances are other drivers would get angry due to the danger and effective width of your car. Examples of logic errors in Java programs include: non-termination of your program because you make it go into a loop that never stops writing a test for the wrong condition (for example writing "if( age < 21 )" rather than "if( age > 21)" when you wish to test if some value is greater than 21 changing the value of a variable to that of another, when in fact you wished to compare the two values -- this is very common due the to similarity of the symbol to change a varibale's value "=", and the symbol to compare two values "= ="
Back to top 
RITSEC - Global Campus Copyright ?1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg |