created 04/27/00

CHAPTER 80 --- Exceptions and Errors

When a program is running there are many problems it might encounter. There may be trouble reading data, or there many be illegal characters in the data, or an array index might go out of bounds. Java has features that enable you to write programs that can deal with such problems. The program can be written recover from some errors and keep on running. This is important in commercial programming. A word processor program cannot stop dead for every input error!

Chapter Topics:

  • Exceptions and Errors.
  • Runtime Exceptions.
  • Arithmetic Exceptions.
  • try, catch, and finally statements.
  • User-friendly programs.

Another reason for looking at this topic is that it is needed if you wish to do I/O programming. This is a topic of a future chapter.

QUESTION 1:

What went wrong when the user ran this program:

D:\cs151\chap80>java  Square 
Enter an integer:
Rats
Exception in thread "main" java.lang.NumberFormatException: Rats
        at java.lang.Integer.parseInt(Integer.java:409)
        at java.lang.Integer.parseInt(Integer.java:458)
        at Square .main(NFException.java:18)

D:\cs151\chap80>
Click Here after you have answered the question