Miller_Rabin.java:24: unreported exception java.io.IOException; must be
caught or declared to be thrown
String t = stdin.readLine();
I'm not sure how to fix this error. someone please help. I have a line
in my code that says:
String t = stdin.readLine();
s = Integer.parseInt(t);
which is the line that's generating the exception
I can provide additional details if necessary
Fabien Bergeret - 07 Nov 2005 10:52 GMT
> Miller_Rabin.java:24: unreported exception java.io.IOException; must be
> caught or declared to be thrown
[quoted text clipped - 9 lines]
>
> I can provide additional details if necessary
try {
String t = stdin.readLine();
s = Integer.parseInt(t);
}
catch(IOException e){
System.err.println("Unable to read from stdin");
}
catch(NumberFormatException e) {
System.err.println("What you typed is definitely not a number");
}
toy - 07 Nov 2005 20:02 GMT
Thanks for your help fabien...can you help me with the same string
error...what do I do?
Bryce - 07 Nov 2005 14:17 GMT
>Miller_Rabin.java:24: unreported exception java.io.IOException; must be
>caught or declared to be thrown
[quoted text clipped - 9 lines]
>
>I can provide additional details if necessary
try {
String t = stdin.readLine();
s = Integer.parseInt(t);
} catch(IOException e) {
// Do something here
}
--
now with more cowbell
toy - 07 Nov 2005 19:14 GMT
what about this line:
String ns = stdin.readLine();
Generatese the same error, except it is a string.
Oliver Wong - 07 Nov 2005 19:45 GMT
> what about this line:
>
> String ns = stdin.readLine();
>
> Generatese the same error, except it is a string.
You might want to read Sun's tutorial on exceptions:
http://java.sun.com/docs/books/tutorial/essential/exceptions/
- Oliver
Ted Present - 07 Nov 2005 21:53 GMT
Try adding "throws IOException" after the method declaration
For example...
<code>
public static void main(String[] args) throws IOException
{
String str = Integer.parseInt(stdin.readLine());
}
</code>
This should at least allow the method to compile. If you want to handle the
error in a specific way, however, use the try...catch block as others have
said.

Signature
Ted Present
presentt@verizon.net
Noodles Jefferson - 08 Nov 2005 04:42 GMT
> Miller_Rabin.java:24: unreported exception java.io.IOException; must be
> caught or declared to be thrown
[quoted text clipped - 9 lines]
>
> I can provide additional details if necessary
No need.
The error message is telling you that you need to either:
a) put throws IOException in your method header
public void whatever() throws IOException {
}
or
b) put a try/catch block in your method.
public void whatever() {
try {
String t = stdin.readLine();
s = Integer.parseInt(t);
} catch (IOException ioe) {
// do something
}

Signature
Noodles Jefferson
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
"Our earth is degenerate in these latter days, bribery and corruption
are common, children no longer obey their parents and the end of the
world is evidently approaching."
--Assyrian clay tablet 2800 B.C.