Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Java Exception Please Help

Thread view: 
toy - 07 Nov 2005 10:47 GMT
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>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.