【问题标题】:Java: why "throw new Exception()" have to "add Exception to method signature" but "throw new RuntimeException()" not [duplicate]Java:为什么“抛出新异常()”必须“将异常添加到方法签名”但“抛出新的 RuntimeException()”不是[重复]
【发布时间】:2014-11-07 08:13:15
【问题描述】:

我试试

package ro.ex;

/**
 * Created by roroco on 11/4/14.
 */

class Ex {

    public void m() {
        throw new Exception();
    }

    public void m2() {
        throw new RuntimeException();
    }
}

throw new Exception(); 中,intellij 的想法引发了“未处理的异常:java.lang.Exception”,但在 throw new RuntimeException(); 中不是,我的问题是:是什么导致了这种差异?

【问题讨论】:

标签: java syntax intellij-idea


【解决方案1】:

请参阅link 了解已检查和未检查的异常

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 2010-10-15
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多