Lesson 2. Errors and Testing
Lesson Objective
- Be able to identify errors in code.
- Specifically Syntax, Logic and Runtime Errors.
Lesson Notes
Errors?
Errors can occur in many algorithms and programs. They can be referred to as bugs. The 3 types of errors you need to be aware of are: Syntax errors, logical errors and runtime errors.
- Syntax Errors: These are grammatical mistakes in the programming language itself, like typos or missing punctuation. They prevent your program from even starting and are usually easy to spot.
- Logical Errors: These occur when your code compiles and runs but produces incorrect results due to flaws in the internal logic. Think of them as following a flawed recipe - the steps are right, but the outcome is wrong. Debugging these can be more challenging.
- Runtime Errors: These errors happen during execution, often due to unexpected conditions like accessing invalid memory or dividing by zero. Imagine a recipe calling for an undefined ingredient or cooking at an impossible temperature - your program crashes unexpectedly.
Knowing these error types and their characteristics will help you identify and fix them more efficiently, leading to smoother development and more reliable code.