File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes error in code please help!!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "error in code please help!!!!!!!" Watch "error in code please help!!!!!!!" New topic

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

sumedha rao
Ranch Hand

Joined: Nov 26, 2010
Posts: 115

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;must be caught or declared to be thrown

Any help would be of great help.

Greg Charles

Joined: Oct 01, 2001
Posts: 2968

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

Joined: Nov 26, 2010
Posts: 115

Hey thanks for the explanation
Problem solved.
I feel so dumb to ask such silly problems...Thanks a lot Greg Charles!!!
I agree. Here's the link:
subject: error in code please help!!!!!!!
It's not a secret anymore!