I have a method which is long and has many inner loops, at some point in the inner loop if a certain condition is met, I want the thread to be terminated but I also want the finally block to be called so clean up also happens. How can I do this?
Share
Call
return;when you want to stop. That will leave the loop and run the finally (so long as the loop with the return statement is within thetryblock).E.g.
pseudocode: