java - 我可以编写 Error 对象以在 catch 块中捕获 Exception 对象吗
问题描述
编写捕获异常对象的捕获块和捕获错误对象的捕获块有什么区别?当我编写 Only Error catch 块时,它执行并捕获异常,结果与异常相同,但是当使用两个 catch 块编写时,它执行异常 catch 块而不是 catch 错误块。有人可以详细解释。
public class Main
{
public static void main(String[] args) {
int a=1,b=0;
try{
System.out.println(a/b);
}catch(Error e){
System.out.println("error"+e);
}
catch(Exceptione){
System.out.println("exception"+e);
}
}
}
解决方案
推荐阅读
- python - 读取 CSV 文件中的多个不同列,并将不同的列名匹配到一个统一变量
- c# - 如果 SQL 搜索查询未能找到值,如何显示消息
- python - Pip 升级 cv2
- c++ - 请求从“Point*”转换为非标量类型“Point”
- c++ - 我为 Evil Hangman 的构造函数遗漏了什么吗?
- react-native - 如何设置标题的背景视图
- google-apps-script - 如何在将在数组内工作的方法中设置参数?(谷歌应用脚本)
- java - 使用 Spring RetryTemplate 时获取当前退避值
- python - 如何将打印的 for 循环值写入 csv 文件?
- python - Python - 当数据不是数字时如何从 csv 文件制作条形图