Error Types and Techniques
Error Types and Techniques
Using your notes from class discussion, your textbook and internet
define with relevant annotated examples the following: -
Error types
• Syntax error
• Logic error
• Runtime error
Error detection techniques
• Flags (to debug errors)
• Debugging output statements
• Stubs
For each dot point you will need to come up with a comprehensive
definitive, 2 annotated examples (explain why the example is
relevant to the explanation of this concept) from either VS Code or
from the command console of the relevant concept/technique.
Syntax Error
-make an error in the grammar of the code
______________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
___________________________________________________________________
________________________
Annotated examples
print ("hello")
print ("hello"
if 2 == 3:
print('hello')
else if 2 == 2:
print('goodbye')
______________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
___
Annotated examples – Inflarile loop
num1 = input("please enter a number")
num2 = input("ple0-ase enter a number")
num3 = input("please enter a number")
avarge = num1+num2+num3/3
int j = 0:
int k = 25/j:
Flag (to debug errors)
- Binary condition T/F, Y/N
- Set at the start of the program and change depending on the input
______________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
_________________________________________________________________ ___
____________________________________________________________________
Annotated examples
____________________________________________________________________
__________________
big_number_flag = False
for i in range(5):
n = int (input("Enter a number"))
if n > 2000:
big_number_flag = True
else:
big_number_flag = False
______________________________________________________________________
____________________________________________________________________
____________________________________________________________________
___________________________________________________________________ _
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
Annotated examples – age?
____________________________________________________________________
________________
def hypotenuse(x, y):
print("x is %f and y is %f" % (x, y))
x_2 = x**2
print(x_2)
y_2 = y**2
print(y_2)
z_2 = x_2 + y_2
print(z_2)
z = math.sqrt(z_2)
print(z)
return z
Stubs
-To down / modular approach to program design we use stubs to “stand in the place”
of module we haven’t developed yet._(flow of the program)
______________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
Annotated examples (use the Mock python library)
_
Main --- error checking – place holders
- Guess modular
- Print-out modular
Mock - library