Presentation is loading. Please wait.

Presentation is loading. Please wait.

Errors “Computer says no..”. Types of Errors Many different types of errors new ones are being invented every day by industrious programming students..

Similar presentations


Presentation on theme: "Errors “Computer says no..”. Types of Errors Many different types of errors new ones are being invented every day by industrious programming students.."— Presentation transcript:

1 Errors “Computer says no..”

2 Types of Errors Many different types of errors new ones are being invented every day by industrious programming students.. Three general categories: compile-time errors linker errors runtime errors Compiler errors are significantly easier to detect and fix, since the compiler tells you what they are and where to find them!

3 Compiler Errors Compiler is just another program, and requires input in the right format 3 classes of compile time errors: lexical errors: ‘words’ cannot be determined syntax errors: ‘grammar’ is incorrect semantic errors: doesn’t make sense! These types of errors are almost identical to those encountered in spoken and written languages..

4 Lexical Errors Compilers work by breaking the source file into tokens when this cannot be done, a lexical error occurs English equivalent: misspelling words, nonsense words, incorrect spacing, etc.. “Thw3#5-ta_lbe ishcy+3i#%!” C example: whilea<130printf(“hello”);

5 Syntax Errors Most common form of compile error Correct grammar of the language has not been applied: no semicolon at end of statement no matching ( ), [ ], or { } incorrect structure of if, while, for statements, etc incorrect number of arguments for operators English example: “The dog brown the fence underneath dug” C example: for ( i = 14 ; i++ ){ printf ( “%d”, i )

6 Semantic Errors Syntax is correct, but meaning of statements makes no sense incorrect argument types incorrect LHS parameters to certain operators C is considerably less strict on semantics than other languages this is a BAD thing for beginner programmers as mistakes are not flagged by the compiler even though they make little sense.. C examples: int a = 14 ; 7 = a ; printf ( a ) ;

7 Linker Errors The C compiler trusts the programmer if they say a function will be available, the compiler assumes it will be and operates as such sometimes warnings will be generated, sometimes not.. The linker however requires that all such functions actually do exist if they do not, errors are generated by the linker these are very different in appearance to compiler errors, and generally are of the form: undefined reference to ‘???????’ Can often be fixed by including the correct library or object file, or fixing spelling mistakes in your code

8 Runtime Errors These errors occur after compilation, when the program is running They can either: crash the system cause incorrect behaviour The second type are known as ‘logical errors’

9 Runtime Errors Typical examples: division by zero accessing invalid memory English equivalent: “Stand up. Lift left leg. Lift right leg.” Logical errors: anything that isn’t correct!!


Download ppt "Errors “Computer says no..”. Types of Errors Many different types of errors new ones are being invented every day by industrious programming students.."

Similar presentations


Ads by Google