原因很简单
是因为你的类方法写到main方法里面了
public static void main(String[]args) {
Test t = new Test();
t.m(0);
void m(int i) throws ArithmeticException {
if(i == 0)
new throw ArithmeticException("被除数为0");
}
}
应该将m这个方法写在main方法外面
现给你改成
public class Test {
public static void main(String[]args) {
Test t = new Test();
t.m(0);
}
void m(int i) throws ArithmeticException {
if(i == 0)
new throw ArithmeticException("被除数为0");
}
}