File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

can anyone answer the why it is

Veshnu Ramakrishnan
Ranch Hand

Joined: Sep 27, 2005
Posts: 44
public class TestClass {

public TestClass() {

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 =;
} catch (ArithmeticException e) {


if we run the above program it wil give "true" as output. can anyone answer

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

Joined: Sep 16, 2004
Posts: 3640
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

Joined: Jul 08, 2003
Posts: 24199

Duplicate of this.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: can anyone answer the why it is
jQuery in Action, 3rd edition