File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested try-finally block

 
Marco Pacini
Greenhorn
Posts: 5
  • 0
  • 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.
 
Nisha Ganeriwal
Greenhorn
Posts: 8
Android Java
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic