Syntax Errors
""" Syntax error refers to the structure and the rules
"""
print(1 + 2
"""
SyntaxError: unexpected EOF while parsing
"""
Runtime Errors
""" Runtime errors does not appear until after the program has started
Those type of errors are called exceptions
"""
first = "Hello"
second = "World"
print(first + " " + secoend)
"""
NameError: name 'secoend' is not defined
"""
Semantic Errors
Semantic errors will not generate errors but it will not do the right thing.
""" Semantic errors will not generate errors but it will not do the right thing.
The program performs concatenation instead of addition
The programmer failed to convert the inputs to integers
"""
a = input('Enter number 1: ')
b = input('Enter number 2: ')
sum = a + b
assert sum == (int(a) + int(b)), "Assertion Failed"
"""
AssertionError: Assertion Failed
"""
Questions and answers
Semantic code errors:
- a) generates runtime errors
- b) do not throws errors
Errors are handled with ...
- a) try / catch
- b) try / except