The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

trouble with try-catch...

Posted by Steve on May 28, 2000 at 11:59 PM

I entered a simple program because it uses a try and catch
statement and I have no experience with the two. Here's the code
as seen in the book. It throws two errors and I cannot find the
answer. Give a holler if you see anything wrong with the code.

Thanks, Steve:

public class Fruit
{
public static void main(String[] args)
{
int numOranges = 5;
int numApples = 10;
int numFruit = 0;

numFruit = numOranges + numApples;

System.out.println("A totally fruity program.");
System.out.println("Total fruit is " + numFruit);

System.out.println("(press ENTER to exit)");
try
{
System.in.read();
}
catch (IOException e)
{
return;
}
}
}

The errors are:

17: Exception java.io.IOException must be caught, or it must be
declared in the throws clause of this method.
System.in.read();
^

19: Class IOException not found.
catch (IOException e)
^



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us