Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java Exception Please Help

Reply
Thread Tools

Java Exception Please Help

 
 
toy
Guest
Posts: n/a
 
      11-07-2005
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

 
Reply With Quote
 
 
 
 
hilz
Guest
Posts: n/a
 
      11-07-2005
toy wrote:
> 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
>



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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      11-07-2005
On 7 Nov 2005 02:47:04 -0800, "toy" <(E-Mail Removed)> wrote, quoted
or indirectly quoted someone who said :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-07-2005
toy wrote:

> 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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments