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