为什么catch块会产生编译器错误?

kau*_*ray 4 java exception try-catch

我有以下人为的代码:

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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

第一个catch块重新抛出捕获的异常.然而,编译器要求"不兼容类型"和"可投掷".为什么会出现此错误?

vis*_*era 10

只需更改您的班级名称 Exception to Exception1.

它看起来像名称冲突的问题.

您的命名约定策略是反对Java标识符定义规则.

意思是,你不能给出已经由图书馆给出的名字.这里,班级名称.