File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Roundup question #132 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Roundup question #132" Watch "Roundup question #132" New topic
Author

Roundup question #132

Greg Higgins
Greenhorn

Joined: Dec 05, 2000
Posts: 3
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).
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20526
    ∞

If an exception is not caught, then the finally block is run and then the exception is passed to the calling method. The rest of the code in the method is not run.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Greg Higgins
Greenhorn

Joined: Dec 05, 2000
Posts: 3
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
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
The confusion here is over the statement "an exception was not caught" This can be slightly ambiguous because does it mean
1. An exception was thrown but not caught
or
2. An exception was not thrown and therefore not caught
Generally speaking, when I have seen "an exception was not caught", I take it as an exception was thrown but not caught becuase the other version wouldn't have an exception in the first place so it would say "an exception was not thrown" or "the try block did not generate an exception." By saying "an exception was not caught" I think it implies that there is an exception, it just wasn't caught.
The real exam is more definative on this I believe and will say whether or not an exception was generated.
Bill
Greg Higgins
Greenhorn

Joined: Dec 05, 2000
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Roundup question #132