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
hilz - 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
This line is not throwing an exception.
This line is causing a comile error because stdin.readLine can throw an
exception at runtime, and need to be caught somewhere.
The compiler error message is telling you what to do:
the excpetion must be either caugth or declared to be thrown.
so either do this:
String t=null;
try {
t = stdin.readLine();
}catch(java.io.IOException exp){ exp.printStackTrace();}
or have the method that this line is called from throw this exception..
and then you have to catch it somewhere else....
it would help to look at the Exceptions documentation on the
java.sun.com website at this time..
HTH
Roedy Green - 07 Nov 2005 10:54 GMT
>String t = stdin.readLine();
> s = Integer.parseInt(t);
>
>which is the line that's generating the exception
It not actually generating an exception, it just POTENTIALLY could. so
you wrap all your io code in something as simple as this:
try {
..code that does I/O...
}
catch ( IOException e )
{
System.err.println(">>>>" + e.getMessage() );
e.printStackTrace();
}
You don't normally wrap a single line in a try catch.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Andrew Thompson - 07 Nov 2005 11:11 GMT
> Miller_Rabin.java:24: unreported exception..
Oh, way yes it was reported - over on c.l.j.help.
Please refrain from multi-posting.
<http://www.physci.org/codes/javafaq.jsp#xpost>