Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in code please help!!!!!!!

 
sumedha rao
Ranch Hand
Posts: 115
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was practising on how to use static methods in java but had some problem in compling the program.

In the program below i want the user to enter(command line arg) the current balance and the ammount he wants to withdraw.

I get the following errors:
line 8 and 11:
unreported exception java.io.IOException;must be caught or declared to be thrown



Any help would be of great help.
Thanks
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch! In the future try to UseCodeTags and UseAMeaningfulSubjectLine. I've added code tags for you to make things easier.

Now, how much do you know about exceptions in Java. There are checked exceptions and unchecked exceptions. IOException is a checked exception, which means if you call something that can throw an IOException, then you need to either put that call in a try block, and follow with a catch block that catches IOException or one of its superclasses, or you need to declare your method to throw IOException or one of its superclasses. If you look at the Javadocs for BufferedReader, you'll find that the readLine() method can throw IOException, so that's your problem. Let us know if that explanation doesn't make sense, and we'll a back up a step or two.
 
sumedha rao
Ranch Hand
Posts: 115
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks for the explanation
Problem solved.
I feel so dumb to ask such silly problems...Thanks a lot Greg Charles!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic