• Post Reply Bookmark Topic Watch Topic
  • New Topic

exception  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • 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: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Does that code even compile?
2) What happened when you tried to run it?
 
Ranch Hand
Posts: 98
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 56600
172
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!