0% found this document useful (0 votes)
82 views8 pages

Error Types and Techniques

The document defines different types of errors in code such as syntax errors, logic errors, and runtime errors, and provides examples of each. It also explains techniques for detecting errors like using flags, debug output statements, and stubs. For each concept, it lists annotated examples from code to illustrate the concept in practice.

Uploaded by

James Lin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views8 pages

Error Types and Techniques

The document defines different types of errors in code such as syntax errors, logic errors, and runtime errors, and provides examples of each. It also explains techniques for detecting errors like using flags, debug output statements, and stubs. For each concept, it lists annotated examples from code to illustrate the concept in practice.

Uploaded by

James Lin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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"

without the bracket at end of the code it will no function

if 2 == 3:
print('hello')
else if 2 == 2:
print('goodbye')

- Else if syntax incorrect


Logic Error
-undesired ouput or result BGT the codeis syntactically correct

______________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
___
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

it’s error, because we haven’t convert input into integer

num1 = input("please enter a number")


num1 = int(num1)
num2 = input("please enter a number")
num2 = int(num2)
num3 = input("please enter a number")
num3 = int(num3)
average = num1+num2+num3/3
print (average)

please enter a number10


please enter a number10
please enter a number10
23.333333333333332
- The average is incorrect, because we didn’t put the brackets
between the num1,num2,num3.
Runtime Error
-Error occurs when we Interpret or compile the code and try to “RUN” the program.
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
_____________________________________________________________________
______
Annotated examples (from the command console) – divide by 0
String str = null:
str str.toLowerCase():

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

# after the loop


if big_number_flag:
print("saw at least one big number")
else:
print("didn't see any big numbers")
- After the loop is finished, all you can say about the big_number_flag is
that it is True or False, depending on ONLY the LAST value input, not
all 5 values.
Debugging output (print) statements
-System output statement -traceback errors

-Program output statement -print command to print value of variables

______________________________________________________________________
____________________________________________________________________
____________________________________________________________________
___________________________________________________________________ _
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
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

You might also like