Java Reference
In-Depth Information
Continued from previous page
other words, when we find ourselves looking for a nonsense word, we use
“foo.”
The New Hacker's Dictionary contains a great deal of historical information
about the origins of jargon terms. The entry for foo includes a lengthy discussion of
the combined term foobar and how it came into common usage among engineers.
If you want to get a flavor of what is there, check out the entries for bug,
hacker, bogosity, and bogo-sort.
An Example Runtime Error
Runtime errors occur when a bug causes your program to be unable to continue exe-
cuting. What could cause such a thing to happen? One example is if you asked the
computer to calculate an invalid value, such as 1 divided by 0. Another example
would be if your program tries to read data from a file that does not exist.
We haven't discussed how to compute values or read files yet, but there is a way you
can “accidentally” cause a runtime error. The way to do this is to write a static method
that calls itself. If you do this, your program will not stop running, because the method
will keep calling itself indefinitely, until the computer runs out of memory. When this
happens, the program prints a large number of lines of output, and then eventually stops
executing with an error message called a StackOverflowError . Here's an example:
1 public class Infinite {
2 public static void main(String[] args) {
3 oops();
4 }
5
6 public static void oops() {
7 System.out.println("Make it stop!");
8 oops();
9 }
10 }
This ill-fated program produces the following output (with large groups of identical
lines represented by “...”):
Make it stop!
Make it stop!
Make it stop!
Make it stop!
Make it stop!
Make it stop!
Make it stop!
 
Search WWH ::




Custom Search