Hey Javaranchers,
when is it neccessary to catch an exception of a method?
In the following program I used the read method which throws the IOException according to SUN
Java API Specification.
When I compile this error occurs:
C:\jdk1.3\bin>javac read_test1.java
read_test1.java:7: unreported exception java.io.IOException; must be caught or declared to be thrown
int ch = System.in.read ();
^
1 error
When is it neccessary to catch an exception of a method?
============================================================
public class read_test1
{
public static void main (
String args[])
{
while (true)
{
int ch = System.in.read ();
if (ch == 'x')
break;
}
System.out.println("x was read.");
}
}
Thanks for any answer.
Thomas
------------------