aspose file tools*
The moose likes Java in General and the fly likes can anyone answer the why it is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

can anyone answer the why it is

Veshnu Ramakrishnan
Ranch Hand

Joined: Sep 27, 2005
Posts: 44
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?


Veshnu<br />SCBCD<br />SCWCD<br />SCJP
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
Can anybody answer me, why this thread posted again when it is already there?
[ October 31, 2005: Message edited by: Chetan Parekh ]

My blood is tested +ve for Java.
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306


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

Joined: Jul 08, 2003
Posts: 24187
    
  34

Duplicate of this.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can anyone answer the why it is