• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Nested try-finally block

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!