About Question enthuware.ocajp.i.v7.2.834 :
Posted: Sun Jan 04, 2015 3:25 pm
Calling method has to declare in its trows clause the same exception as in the source method, or it could be a super class of that exception?
Java Certification Resources and Java Discussion Forum
https://enthuware.com/forum/
Exception in thread "main" java.lang.Exception
at com.teo.exam.tt.TestClass.yourMethod(TestClass.java:14)
at com.teo.exam.tt.TestClass.myMethod(TestClass.java:10)
at com.teo.exam.tt.TestClass.main(TestClass.java:6)
Code: Select all
public class TestClass {
public static void main(String[] args) throws Exception {
TestClass tc = new TestClass();
tc.myMethod();
}
public void myMethod() throws Exception {
yourMethod();
}
public void yourMethod() throws Exception {
throw new Exception();
}
}