• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

return in Catch and finally block

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Pls look at the code below,

Here, whether exception araises or not,finally block will be executed.I am bit confused here, what is the use of return statement in catch block, anyway it is not going to return that value.
Hope anyone will help me.
[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ January 22, 2003: Message edited by: Jessica Sant ]
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So -- your rule to remember here is: finally is ALWAYS executed. No matter what.
If you adjust your code a bit, and comment out the return statement in the finally block (and add one OUTSIDE of the try block so the compiler doesn't complain) you'll notice that 420 is returned.
Basically... its bad practice to have multiple return statments -- it gets confusing to know which one will be executed (as evidenced very nicely by your lil example).
don't know if that quite answers your question... lemme know.

[ January 22, 2003: Message edited by: Jessica Sant ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right there is no use of return in the catch if there is return in finally.
 
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic