Unit 5 -- Csc 115 Spring 2005 SO1/S02
Learning Objectives for this unit
- Learn the basic principles of testing
- Learn how to manually debug and test your programs
- Learn how use the debugger in Gild
- Learn how to use exceptions and design more robust code
Learning Resources for this week
Lecture slides:
5-Testing.ppt
Sample programs as found in the source directory of this project.
There are also some cool examples this week in activities (see below).
- To demonstrate different kinds of errors (compile, run and logical errrors):
- To demonstrate how to write and use exceptions:
- To gain experience with the Gild debugger, use this example and debug it:
Reading Assignment:
Read Chapter 2.3
Activities:
Short Answer Questions
Answer the following questions:
1) What are the three types of errors? Can you give an example of each type?
2) Where are exception objects created? (Stack or heap?)
3) Why would someone use Exceptions?
4) What happens when an exception is created, but not caught?
5) We have a function divide() and we want to catch any exceptions that divide
by zero (ArithmeticException), fill in the code below:
public static double divide(int m, int n) _________________________ {
double quotient = 0;
_______
{
quotient = m/n;
}___________________________{
System.out.println(e);
}
return quotient;
}
Problems in the textbook, Chapter 2:
Do problem R-2.9 in edition 3 of the textbook which is: Give an example of a Java code fragment
that performs an array reference that is possibly out of bounds, and if it is out of bounds, the program
catches that exception and prints the following error message: "Don't try buffer overflow attacks
in Java!".
Go to the course website