[5799] in java-interest
Re: Exception handling and throwing
daemon@ATHENA.MIT.EDU (Vitor Carreira)
Tue Feb 27 01:57:40 1996
From: Vitor Carreira <vmc@lila.dei.uc.pt>
To: mcdaniel@umich.edu (Susan McDaniel)
Date: Tue, 27 Feb 1996 07:12:08 +0100 (GMT+0100)
Cc: java-interest@java.sun.com
In-Reply-To: <Pine.SUN.3.91.960226141840.1771C-100000@geneva.crew.umich.edu> from "Susan McDaniel" at Feb 26, 96 02:19:49 pm
Susan McDaniel wrote:
>
>
> I'm trying to do file i/o and am having some trouble with exceptions. I know
> how to use the try{}catch{}finally{} stuff (or at least I think I do). But
> the error message from the compiler says:
>
> Exception java.io.IO Exception must be caught, or it must be declared in the
> throws clause of this method.
>
> What is a throws clause? How do I invoke one? The error is occuring in the
> following line of code:
>
> RandomAccessFile file = new RandomAccessFile(input, "rw");
> ^
>
You must do something like that:
try {
RandomAccessFile file=new RandomAccessFile(input, "rw");
.....
} catch (IOException e) {
do something about the error
}
If you don't want to catch the exception in this method you must throw it.
Example:
void methodx() throws IOException {
....
}
Remember that if you throw the exception some method on the stack call must deal
that exception.
If you want more information try out http://lila.dei.uc.pt/~vmc/
If you want to go directly to the Exception part try
http://lila.dei.uc.pt/~vmc/Tutorial3/java/exceptions/
Good luck!
---------------------------------
Vitor Carreira
vmc@lila.dei.uc.pt
http://lila.dei.uc.pt/~vmc
---------------------------------
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com