aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
Given:
1 public class Test {
2 public static String output ="";
3
4 public static void foo(int i) {
5 try {
6 if(i==1) {
7 throw new Exception();
8 }
9 output += "1";
10 }
11 catch(Exception e) {
12 output += "2";
13 return;
14 }
15 finally {
16 output += "3";
17 }
18 output += "4";
19 }
20
21 public static void main(String args[]) {
22 foo(0);
23 foo(1);
24
25 }
26 }
What is the value of the variable output at line 23?
bibby young
Greenhorn

Joined: Aug 05, 2005
Posts: 4
From my point of view it should be
"134234".
After the first invocation,it's "134",because the "finally" block always runs.
And line 23 adds "234" to the string.
Please correct me if any mistake!!
[ December 18, 2005: Message edited by: bibby young ]

坚持就是胜利!
Navjeet Nehra
Greenhorn

Joined: Sep 18, 2003
Posts: 13
As the last line in the catch block is return. The output would include the last "4"
xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
young ,are you chinese?
i am
Sudhir palavalasa
Greenhorn

Joined: Nov 29, 2005
Posts: 4
The output would be "13423". The "4" at last will NOT be included, because of the "return" statement in the catch block.Only finally block will be executed after "return".Please check.

Regards,
Sudhir
xie li
Ranch Hand

Joined: Nov 30, 2005
Posts: 54
thanks
 
jQuery in Action, 2nd edition
 
subject: Exception