• 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

exception

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what will be output and when it will return after completing execution of catch block or after completing execution of finally block

thanks in advance
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Does that code even compile?
2) What happened when you tried to run it?
 
Ranch Hand
Posts: 104
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A finally block will always execute before control is returned to the caller. So assuming your try is successful you will see the print for the try followed by the finally print. If your try throws an exception, then the catch print will be shown, followed by the finally block. But as Maneesh suggested, run some examples on your local machine and see what happens.

The following example is a bit better for showing a catch block at work than your example. Your example will be fine for showing the try being successful.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you got that code to compile, which you might manage by changing return3; to return 3; you would find what bad design it is to return something from a finally. You would (at least I think you would) always get the same result from that method regardless. I shall let you compile it so you can see for yourself.
 
reply
    Bookmark Topic Watch Topic
  • New Topic