aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Try/catch/finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Try/catch/finally" Watch "Try/catch/finally" New topic
Author

Try/catch/finally

Venkatesh Gowri
Greenhorn

Joined: Aug 15, 2002
Posts: 12
Hello
I have a doubt regarding Try/catch and Finally .
Now will "Finally" execture even if there is no catch block after Try.
That is if The runtime System throws an exception Due to the absence of the Catch Block will the Finally Block Still be Executed.?

Now in the above example i have commented the catch block but this is the output i get an Arithmetic Exception but the finally block never gets exectued.
can u please Help me
thanks


Gowri Venkatesh
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
The finally gets executed always, if it is present, except special cases like, System.exit
Even in ur example also, the output is
Hello
Exception in thread "main" java.lang.ArithmeticException: / by zero
at divbyzero.main(divbyzero.java:9)
It directly goes to Finally block as the exception is not caught and exceutes finally and gives exception.
HTH


MT
Tauqueer Ali
Ranch Hand

Joined: Sep 05, 2001
Posts: 53
this code doesn't even compile
gives the following error message while compiling
cannot compute value of expression: class Error const *.


SCJP2, SCWCD, XML, OOAD<br />Kolkata, India
suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
The code compiled and raised Arithemetic exception after printing Hello on the screen.
Sample output.
--------------
Hello
Exception in thread "main" java.lang.ArithmeticException: / by zero
at test.main(test.java:9)
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
I get:
divbyzero.java:9: Arithmetic exception.
int y=10/0;
at compile time.
Do different compilers act differently when they see constant integer division by 0?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
suresh kamsa
Ranch Hand

Joined: Jul 30, 2001
Posts: 149
The code compiled and raised Arithemetic exception after printing Hello on the screen.
Sample output.
--------------
Hello
Exception in thread "main" java.lang.ArithmeticException: / by zero
at test.main(test.java:9)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Try/catch/finally