java - `finally`中的断点没有被命中
问题描述
我正在搞乱一些try...catch...finally
处决,并注意到finally
似乎不会命中断点:
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");
}
中的断点finally
似乎没有命中,但它打印成功。
但是,如果我将 更改try
为int num = 5 / 1;
,因此不进入catch
,则断点被命中。
我正在使用 Netbeans 8.1。
是否有一个原因?
解决方案
正在发生,因为在 catch 中,如果您看到代码,您将无限循环抛出函数
exampleMethod() 正在调用 exampleMethod2() 和 exampleMethod2() 调用 exampleMethod() 所以你有一个带有函数的循环,这就是你得到 StackoverFlowError 的原因
尝试不调用自身的函数
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() {
}
在这个例子中,刹车点终于命中了
推荐阅读
- reactjs - 在 axios/react 中调用 .then
- build - 构建 ambari 2.7.5 Centos 7 时出错(在 ambari-admin 步骤失败)
- oracle - 如何创建动态填充表中缺失数据行的视图
- java - split 方法如何创建 PairFunction?
- mysql - 返回 SQL 中特定行的计数
- python - 有没有办法阻止 QWindowsNativeFileDialog::OnSelectionChange(Qurl...) 退出命令行?
- sql - 如何在 WP_Query 中搜索标题、内容或元数据?
- r - 在带有 add_scatterplot 的点击事件期间,R 中的 Mapdeck 究竟返回了什么?
- html - 在调整窗口大小时调整元素大小
- python - 关于 range() 的 for 语句的问题