• 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

nested try , catch , finally blocks ???

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have

If it is caught in the inner try block then will the outer finally block be called?
And if you throw an exception from the first catch block where does it go. Is it like an exception occuring in the outer most try block so it goes to the outer most try block or is it go to the next catch block in the inner try that is of that type assuming you have one?

Some questions
If you have nest finally blocks then if the inner most finally is called does the outer ones get called as well or do you have to rethrow it?
If the outer most try block gets called then then does the inner finally blocks get called?
If you catch an exception in the inner try block and throw an exception does the new exception get caught in one of the parent try blocks?
What happens if you throw a new exception that is a superclass of any exceptions that the parent catch blocks can catch?


[HENRY: Add Code Tags, And formatted code]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to learn is to experiment. Try putting some code that throws exceptions inside your try block and see what happens. Try different exceptions/multiple catch blocks/no catch block (just a try and finally).
If you get any results you weren't expecting or don't understand, then come back and ask about them specifically.

Joanne
 
Sam Doder
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I figured out most of the questions but I still don't know about the finally block.
Does it get called automatically after you leave the try block. Or After you leave the entire function.
And will the finally block be always called no matter where it is or how many nested try blocks you have?
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you feeling brave? If so, try the Java Language Specification.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic