About Question enthuware.ocajp.i.v7.2.846 :
Posted: Wed Mar 21, 2012 10:53 pm
Look at this question:
public class TestClass {
public static void doStuff() throws Exception{
System.out.println("Doing stuff...");
if(Math.random()>0.4){
throw new Exception("Too high!");
}
System.out.println("Done stuff.");
}
public static void main(String[] args) throws Exception {
doStuff();
System.out.println("Over");
}
}
The program says that the correct answers are:
Doing stuff...
Exception in thread "main" java.lang.Exception: Too high!
at TestClass.doStuff(TestClass.java:29)
at TestClass.main(TestClass.java:41) Agreed
AND
Doing stuff...
Done stuff. Not agreed
My point is: if the program reaches the "Done stuff", isn't it obligated to run the "Over"?
public class TestClass {
public static void doStuff() throws Exception{
System.out.println("Doing stuff...");
if(Math.random()>0.4){
throw new Exception("Too high!");
}
System.out.println("Done stuff.");
}
public static void main(String[] args) throws Exception {
doStuff();
System.out.println("Over");
}
}
The program says that the correct answers are:
Doing stuff...
Exception in thread "main" java.lang.Exception: Too high!
at TestClass.doStuff(TestClass.java:29)
at TestClass.main(TestClass.java:41) Agreed
AND
Doing stuff...
Done stuff. Not agreed
My point is: if the program reaches the "Done stuff", isn't it obligated to run the "Over"?