【发布时间】:2015-11-26 05:40:54
【问题描述】:
我有以下人为的代码:
class Exception
{
public static void main(String args[])
{
int x = 10;
int y = 0;
int result;
try{
result = x / y;
}
catch(ArithmeticException e){
System.out.println("Throwing the exception");
throw new ArithmeticException();
}
catch(Exception ae){
System.out.println("Caught the rethrown exception");
}
}
}
第一个 catch 块重新抛出捕获的异常。然而,编译器说需要“不兼容的类型”和“可抛出的”。为什么会产生这个错误?
【问题讨论】:
-
在
catch(Exception ae)中,它将Exception识别为您自己的类。 -
重命名类,让它与众不同。比异常