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.

19th Oct 2016, 8:53 AM
Siddhant Prabhu
Siddhant Prabhu - avatar
4 Respuestas
+ 3
System.exit(0);
19th Oct 2016, 9:31 AM
Akash Middinti
+ 1
It's very simple. Just remove finally statement. ex) try{...}catch{...}
21st Oct 2016, 3:41 PM
Junsu Seo
Junsu Seo - avatar
+ 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.
2nd Nov 2016, 2:22 AM
Siva Prasad
Siva Prasad - avatar
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?
19th Oct 2016, 9:51 AM
Siddhant Prabhu
Siddhant Prabhu - avatar