Syntax errors
Are errors in the code that the computer cannot interpret, and then the program stops.
In Python these errors are often:
- Spelling errors
- The omission of important characters (such is a missing colon)
- Inconsistent use of ‘/’ or wrong indentitation
Examples
In the first one is missing the parenthesis, printing EOF error or End Of File error
In the second one there are two errors, missing colon and no indentation
Runtime errors
These are errors that are not detected until runtime.
These are often caused by:
- It can’t find some date because it doesn’t exist
- It can perform an action on the data it has been given because it is an invalid type of data
Typical runtime errors are:
- Division by zero
- Performing an operation on incompatible types
- Using an identifier which has not been defined
- Accessing a list element, dictionary value or object attribute which doesn’t exist
- Trying to access a file which doesn’t exist
This type of errors are only found at runtime and often through lots of testing.
Examples
- Division by zero: Impossible!
- Data type error: Input a string that must be converted to integer
- Indexing error: Python starts indexing lists from 0. The ‘sugar’ item is the number [2]
There was a runtime error in converting between a floating point number and an integer, that caused a $370 million lost in 45 second (video) [ + ]
Logical or semantical errors
These are errors in the code that do not throw an error at all, but simply do not do what you intended the code to do. The program doesn’t crash. These are the most difficult to spot, because they can only be found trough full and extensive testing.
Examples
- Operator in the wrong direction and must be switched to have a correct logic output
In September 1999, after almost 10 months of travel to Mars, the Mars Climate Orbiter burned and broke into pieces. On a day when NASA engineers were expecting to celebrate, the ground reality turned out to be completely different, all because someone failed to use the right units, i.e., the metric units! The Scientific American Space Lab made a brief but interesting video on this very topic [ + ].