[6222] in java-interest

home help back first fref pref prev next nref lref last post

Re: Handling Exceptions - doubts ....

daemon@ATHENA.MIT.EDU (Jeff Marin)
Mon Mar 25 21:00:47 1996

Date:         Mon, 18 Mar 1996 23:12:26 -0500
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Jeff Marin <jmarin@MARS.SUPERLINK.NET>
To: Multiple recipients of list JAVA-INTEREST
              <JAVA-INTEREST@JAVASOFT.COM>

Dhaval M Shah wrote:
>
> Hello Everybody,
>
> I am not able to compile this code, because the compiler says....
>
> -----
> >filewindow.java:71: Exception java.io.IOException must be caught, or it must be declared in the throws clause of this method.
>     fh.openfiles(infilename,indirectory);
>                 ^
> >1 error
> -----
>
> While my program code is like this :
>
> -----
>
> class Filehandler
> {
>  public void openfiles(String infile, String indir)
>         throws java.io.IOException
>  {
>     File newfile = new File(indir, infile);
>     FileInputStream fis = new FileInputStream(newfile);
>     FileOutputStream fos = new FileOutputStream(newfile);
>     System.out.println("First Byte read is : " + fis.read());
>  }
> }
>
> public class filewindow extends frame
> {
>   .....
>   .....
>
>   public boolean handleEvent(Event event)
>   {
>    ....
>    ....
>
>     Filehandler fh = new Filehandler();
>     fh.openfiles(infilename,indirectory);
>   }
>
>   ....
> }
>
> -----------
>
> Can somebody point out where I am going wrong - since I have decl.
> java.io,IOException for void openfiles.
>
> Thanks
>
> Dhaval
> --
> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
>    Dhaval M. Shah
>    dms03@cs.uow.edu.au                 (Home) : +61 42 258519
>    Dept. of Computer Science
>    University of Wollongong             2/13 Catherine St., Gwynneville,
>    NSW 2522     Australia               NSW 2500     Australia
> =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

Try using try :) around the fh.openfiles line.  You have correctly
declared the openfiles functions as throwable but then yuou do not
follow it up by catching the Exception it may throw.
--
************************************************************************Jeff Marin                              jmarin@superlink.com
@Work Technologies                      http://www.worktechs.com
< "To err is human, to not learn JAVA mentally healthy but unavoidable!"
>

-----
This message has been forwarded via the JAVA-INTEREST
mailing list.  In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).

-----
This message has been forwarded via the JAVA-INTEREST
mailing list.  In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).

home help back first fref pref prev next nref lref last post