• 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-finally block

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm studying Exception Handling but i don't understand what happen in this code:
i wrote it to understand what happen when there are nested try block but i don't understand why InterruptedExcetion and ArrayStoreException aren't catched.
 
Greenhorn
Posts: 8
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how the try-finally block(Exception not caught) is handled: try block is executed. If theres is an exception, it is noted(I am not very sure on how) and the control is transferred to the finally block. After successful completion of the finally block the exception is passed on.

In your code, there is an exception(ArrayStoreException) in the inner-inner finally or the inner-try, this is noted and the inner-finally executed. Now inner-finally doesn't complete successfully so exception(ArrayStoreException) is forgotten(if it is correct to use the word). Now InterruptedException which occured in the try block(or inner-finally) is noted and control transferred to the outermost finally where Arithmetic Exception occurs causing finally to end abruptly and InterruptedException being forgotten. the Arithmetic Exception which occurred in the finally-block is now passed on for handling.

Section 7.13 on the page explains how this exactly works.

To summarize, if finally ends abruptly, any exception in the try block is forgotten.

I hope that made some sense.
 
reply
    Bookmark Topic Watch Topic
  • New Topic