I was messing around with some try...catch...finally
executions and noticed a breakpoint in finally
won't seem to be hit:
try {
System.out.println("in try");
int num = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("in catch");
} finally {
System.out.println(); //breakpoint here
System.out.println("in finally");
}
The breakpoint in the finally
doesn't seem to hit, however it prints out successfully.
However, if I change the try
to int num = 5 / 1;
, and therefore not going in to the catch
, the breakpoint is hit.
I'm using Netbeans 8.1.
Is there a reason for this?
is happening because in catch you are infinitely looping throw functions if you see your code
exampleMethod() is calling exampleMethod2() and exampleMethod2() calling exampleMethod() so you have a loop with function thats why you get StackoverFlowError
try to functions not call itself
public static void main(String[] args) {
SpringApplication.run(AuthApplication.class, args);
try {
System.out.println("in try");
int num = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("in catch");
exampleMethod();
} finally {
System.out.println(); // <--- breakpoint here
System.out.println("in finally");
}
}
static void exampleMethod() {
}
in this example brakepoint hit in finally
According to this answer finally is skipped because the infinite recursion (also this question might be a duplicate of that)
Or if not i think you should recompile the whole project. So even if you delete that function call, maybe the compiled classes still have that infinite recursion.
EDIT
Here is the proof that it works. So please try to recompile it, delete caches, etc, or please give us a bit more description about the exact problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.