Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question on "Throw"

807601Jul 1 2008 — edited Jul 1 2008
Hello there,

I did a reading on a couple of internet pages regarding differences between throws and throw on pages like this and this
I understand that throws is used in a method declaration, where the method can specify what exception it throws
public void loadFile throws FileNotFoundException(){
//code for loading file
}
which ever class calls this method will have to definitely surround this method call within a try and catch clause.
Two questions

1) if the class's method which is calling this method is defined as
public void fileMagic throws IOException(){ //assuming IOException is parent for filenotfoundexception
loadFile();
}
then, who catches the error ?
2) if I use a throw in the catch clause like :
public void fileMagic { //assuming IOException is parent for filenotfoundexception
try{
loadFile();
}catch(FNFException f){
throw f;
}
}
then, where am I throwing f to, and who will catch f ?

Please help me understand.

thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 29 2008
Added on Jul 1 2008
4 comments
194 views