created 04/27/00; revised 07/06/02, 06/07/03

CHAPTER 80 — Exceptions and Errors

A program often encounters problems as it executes. It may have trouble reading data, there might be illegal characters in the data, or an array index might go out of bounds. Java Errors and Exceptions enable the programmer deal with such problems. You can write a program that recovers from errors and keeps on running. This is important. A word processor program should not crash when the user makes an error!

Chapter Topics:

Input and output is especially error prone. Exception handling is essential for I/O programming, the topic of upcoming chapters.

QUESTION 1:

Inspect the following. What went wrong?

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>