This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
The finally block does not terminate the terminate the program unless you have explicitly called System.exit() inside it. When you want some code to execute, when after some exception is generated in the corresponding try block, you put that code in the finally block.
If you can tell us your problem in detail, we can offer some suggestions.
The finally block is basically DEFINED as code that you want to always run. so, basically, you are asking
how do i not run code that i want to always run?
the obvious answer is that if you don't want it to always run, don't put it in the finally block. Nobody is forcing you to even HAVE a finally block. The question just doesn't make sense. That's why people are asking you what you REALLY want to do.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
The short answer is: you can't. The only way to skip the finally block is by terminating the JVM on the spot - using System.exit, crashing it (through some buggy native code), terminating it from outside (using task manager / kill) or by crashing the entire operating system itself.
Rob Prime wrote:The short answer is: you can't. The only way to skip the finally block is by terminating the JVM on the spot - using System.exit, crashing it (through some buggy native code), terminating it from outside (using task manager / kill) or by crashing the entire operating system itself.
Ken Blair (in his 3rd post) in this old thread found another way of skipping the finally
If they switch on the LHC and it produces a black hole that swallows the Earth, and your computer falls into the black hole just at the moment before it's about to go to the finally-block, then it will be prevented from running!