0
How do i design my code such that i don't want finally block to be executed?
If at anytime I don't want finally block to be executed what code can i write in the program and alter the regular flow so that finally won't be executed.
4 odpowiedzi
+ 3
System.exit(0);
+ 1
It's very simple. Just remove finally statement. ex) try{...}catch{...}
+ 1
Finally is optional code block. You can avoid writing it. Compiler will not complain about it. But it is good programming practice to use it to do lot of house keeping stuff like closing files and releasing resources etc. It is about choice.
But as per your question, you don't want it to be executed even if you write it.
Even though it is stupid to do like I am saying, still want to do - you can use monitors in the try /catch blocks and put the finally inside if clause.
0
Thanks Akash Middinti.. but i want to know is there any other way to not terminate the program but still not execute the finally block? if any?