praveen kumar gowda wrote:i have doubt in two conditon....wheather the statment get executed
I assume you meant to say statement(s) after finally block.
Well,
programmatically, only thing which can stop finally block from execution is - if try and/or catch block contains a call to system.exit and that call is getting executed (e.g. if catch contains system.exit, but there's not exception, then finally block will be executed). There are non-programmatic things which can prevent finally block from getting executed - like JVM crash, OS crash, catastrophic failure, non-maskable interrupt (say power supply is disconnected) etc.
Now, about statement(s)
after finally block:
1) If exception(s) occur
in finally block, and those exceptions are handled, and no new exceptions are thrown from catch block, then those statements(statements after finally block) get executed.
2) If exception(s) occur
before finally block, and those exceptions are handled, and no new exceptions are thrown from catch block, then those statements(statements after finally block) get executed.
In your code, you are not catching any exception in first catch block. So, if any exception occurs there, statements after finally block will not be executed.
In your finally block, you are handling only IOException. So, if any other exception occurs, then statements after finally block will not be executed.
By the way (its not related to your question, but) if your openFile says that it
throws IOException, then inside
instead of doing
something clever, you can simply
I hope this helps.