This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!

Greg Higgins

Greenhorn
+ Follow
since Dec 05, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Greg Higgins

Thanks for the explanation. When I read the question my assumption was that there was no exception thrown, which is why I thought there was an error here. The ambiguity got me.
19 years ago
Maybe I misunderstood the question. I believe the answer should be FALSE. I created and ran the following test program:
class Test {
public static void main(String[] args) {
Test t = new Test();
t.test(false);
}
public void test(boolean throwException) {
try {
throwException(throwException);
} catch (Exception e) {
System.out.println(e.getMessage());
return;
} finally {
System.out.println("executed finally");
}
System.out.println("after the block");
}
public void throwException(boolean throwException) throws Exception {
if(throwException)
throw new Exception("exception thrown");
}
}
The resulting output is:
executed finally
after the block
An exception was not caught, and the remainder of the method was not skipped, thus the line �after the block� was printed. Changing the parameter to true will cause the remainder of the method to be skipped and the following output:
exception thrown
executed finally
19 years ago
I think there is an error with the following question and answer.
(#132) TRUE or FALSE: if an exception is not caught, the finally block will run and the rest of the method is skipped.
Answer: TRUE The finally block will always run if an exception is thrown, and then the exception is immediately passed to the calling method.
The question states if an exceptions is �not� caught, but the answer states what occurs if an exception is thrown.
If an exception is caught, the finally block will run and the remainder of the method is skipped. However, if an exception is �not� caught, the finally block will run, but the remainder of the method is will not be skipped (unless the finally block does something to halt execution).
19 years ago