91热爆

Syntax, execution and logic errors

There are three types of error that you need to understand.

Syntax error

This is an error in the spelling or grammar used when coding. Missing a letter, character or forgetting to include inverted commas/speech marks are common examples of syntax errors. A syntax error will be identified by an interpreter as it will be unable to convert the source code into machine code.

Execution error

Sometimes called a runtime error, execution errors only become evident during run time. An execution error occurs when a program is asked to do something that it cannot, resulting in a 鈥榗rash鈥. The widely used example of a run time error is asking a program to divide by 0.

The code contains no syntax or logic errors but when it runs it can't perform the task that it has been programmed to carry out. Another example is where an attempt is made to access an item in an array which does not exist eg item 11 in an array with only ten elements.

File handling can also result in execution errors, most often when an attempt is made to write to a file that does not exist.

Logic error

An error in the logic of the code such as using 藗 instead of 藘 or AND instead of OR. The program will execute the code but will produce unexpected results. Logic errors are usually resolved by carrying out a dry run, using a trace table or setting breakpoints to help identify the section of code that contains the logic error.