IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
Author

Return statement in try and finally block. How it works

Raveendran Hs
Greenhorn

Joined: Feb 05, 2010
Messages: 1


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
Messages: 126

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
Sheriff

Joined: Jan 10, 2002
Messages: 36596

"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
Messages: 7193

Moving to a more suitable forum.
Wouter Oet
Ranch Hand

Joined: Oct 25, 2008
Messages: 500

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
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Java in General
 
RSS feed
 
New topic
replay challenge