File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic

can anyone answer the why it is

 
Veshnu Ramakrishnan
Ranch Hand
Posts: 44
  • 0
  • 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
  • 0
  • 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: 306
  • 0
  • 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: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate of this.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic