【发布时间】:2016-04-22 01:53:07
【问题描述】:
我有一个名为的表名列表:
List<String> tables = Lists.newArrayList();
我想做的是创建一个连接,然后一个一个地删除所有表。
我的问题是在 stmt.exceuteUpdate(sql) 行 eclipse 中要求我捕捉 SQLException。但是当我尝试抛出同样的异常时,
eclipse 在说:未处理的异常类型 SQLException
在我的方法声明中:
throws Exception, SQLException
请帮助我。可能是什么问题?
try (Statement stmt = data.db.getConnection().createStatement()) {
tables.stream().forEach(tableName -> {
String sql = " DELETE FROM " + tableName;
int deletedRows = 0;
try {
deletedRows = stmt.executeUpdate(sql);
} catch (Exception e) {
throw e; // eclipse says: Unhandled exception type SQLException
}
});
我尝试在使用throw e; 时同时捕获 SQLException 或 Exception。但是 eclipse 将此标记为错误!
如果我不使用throw e;,eclipse 不会将其标记为错误,但我确实需要在那里抛出异常。
可能是什么问题?
【问题讨论】:
-
throw new RuntimeException(e);如果您只想不检查异常 -
这里似乎根本不需要使用 lambda 表达式。
for (String tableName : tables)完全一样。
标签: java eclipse exception lambda