I have class A in which I have a method openfileConnec(). It was written like the below:
public void openfileConnec() throws Exception {
//code for opening a file
}
Now I come to class B where I will call this method like the below:
class B {
try {
openfileConnect()
}
catch(Exception e) {
}
}
I was asked a question in an interview as follows:
- Why does the method have a throws Exception in its declaration? Is it that on of the methods called in the implementation throws the base class exception?
- Also If we get a exception during calling the method (fileConnect( )) control goes to catch block. After executing catch where should the control go, what should be sent to base case?
Can any one help me in sorting out this issue? Thanks in Advance.