【发布时间】:2013-09-16 20:13:55
【问题描述】:
在第一个 catch 块中,为什么我们不能抛出 Exception 对象?这里RuntimeException 工作正常。
public class CirEx {
public Circle getCircle(int id) {
Connection conn = null;
try {
Class.forName("");
conn = DriverManager.getConnection("");
PreparedStatement pstmt = conn.prepareStatement("");
Circle circle = new Circle(1, "");
return circle;
} catch (Exception e) {
throw new RuntimeException(e);
// why we cann't do that.
// throw new Exception(e);
} finally {
try {
conn.close();
} catch (SQLException e) {
System.out.println(e);
}
}
}
}
【问题讨论】:
-
请用标题描述您的实际问题。
-
这是一个格式错误的问题(因为标题),这段代码根本没有问题。