Java 未抛出可丢弃的实例

Java 未抛出可丢弃的实例,java,exception,exception-handling,Java,Exception,Exception Handling,我在某个地方读过这段代码,当我在netbeans中编写它时,它正在打印所需的输出,但显示了一条警告“Throwable instance not Trown” 谁能告诉我为什么会显示此警告。我要感谢QBrute指出错误 正确代码 class Demo { public static void f1() throws MyException { throw new MyException(); // I forgot to add parenthesis. }

我在某个地方读过这段代码,当我在netbeans中编写它时,它正在打印所需的输出,但显示了一条警告“Throwable instance not Trown”


谁能告诉我为什么会显示此警告。

我要感谢QBrute指出错误

正确代码

class Demo {

    public static void f1() throws MyException {
        throw new MyException(); // I forgot to add parenthesis.
    }

    public static void f2() throws MyException {
        f1();
    }

    public static void f3() throws MyException {
        f2();
    }

    public static void main(String[] args) {
        try {
            f3();
        } catch (Exception e) {
            System.out.println("Exception in handled in main method");
        }
    }
}

class MyException extends Exception {

}

抛出新的MyException()你忘记了括号。好的,谢谢回复
class Demo {

    public static void f1() throws MyException {
        throw new MyException(); // I forgot to add parenthesis.
    }

    public static void f2() throws MyException {
        f1();
    }

    public static void f3() throws MyException {
        f2();
    }

    public static void main(String[] args) {
        try {
            f3();
        } catch (Exception e) {
            System.out.println("Exception in handled in main method");
        }
    }
}

class MyException extends Exception {

}