File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Return statement in try and finally block. How it works Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Return statement in try and finally block. How it works" Watch "Return statement in try and finally block. How it works" New topic
Author

Return statement in try and finally block. How it works

Hs Raveendran
Greenhorn

Joined: Feb 05, 2010
Posts: 23


Output is:
Hi welcome
2

how this program, escaping return statement from try block.. Please tell me how it works
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

finally will always be executed after try..
And you have a return in the finally, hence the function returns that value.

http://java.sun.com/docs/books/tutorial/essential/exceptions/finally.html


- Chinna
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

"Raveendran Hs", please check your private messages for an important administrative matter.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

Moving to a more suitable forum.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Chinna Eranna wrote:finally will always be executed after try..

One small exception: if the try block calls System.exit() then the finally block will not run.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
 
subject: Return statement in try and finally block. How it works
 
Threads others viewed
Reg. unreachable code
Exception
behaviour of finally
Exception Debug issue for return
try, catch,finally
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com