Bookmark Topic Watch Topic
  • New Topic

can anyone answer the why it is

 
Veshnu Ramakrishnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Report post to moderator
public class TestClass {

/**
*
*/
public TestClass() {
super();
}

public boolean foo() throws ArithmeticException {
try {
int Nan = 1 / 0;
} catch (ArithmeticException e) {
throw e;
} finally {
return true;
}

}

public static void main(String[] args) {
TestClass test = new TestClass();
boolean result = false;
try {
result = test.foo();
} catch (ArithmeticException e) {
e.printStackTrace();
}

System.out.println(result);
}

}
if we run the above program it wil give "true" as output. can anyone answer
Why?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can anybody answer me, why this thread posted again when it is already there?
[ October 31, 2005: Message edited by: Chetan Parekh ]
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Report post to moderator


finally will always be executed no matter an exception occurs or not. This is the reason why method returned true.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate of this.
 
    Bookmark Topic Watch Topic
  • New Topic