请问为什么错误出现在第 13 行作为未报告的异常,必须捕获并声明为抛出
class Demo {
public static void main(String args[]) {
try {
int x = 43 / 0;
} catch (ArithmeticException ob) {
throw ob;
}
try {
int x = 43 / 0;
} catch (Exception ob) {
throw ob;
}
Exception ob = new Exception();
throw ob;
// Line 13 unreported exception Exception; must be caught or declared to be thrown
}
}
最佳答案
您需要向前面提到的抛出异常的方法以及调用该方法的所有方法添加一个throws
关于java - 为什么我收到未报告的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56905682/