异常这部分还是不太熟,在DAO中出现SQLEXCEPTION异常,如何使之通知业务层
我做了一个DAO类DAO方法
public void doExec(String sql_IDU) throws SQLException {try
{
.......
} catch (SQLException SQLe) {
status = SQLe.getMessage();
throw new SQLException()
} finally {
}
}业务层调用
public boolean deleteCompany(String companyId) throws SQLException{
try {
......
dao.doExec(sql.toString());
result = true;
} catch (Exception e) {
System.out.println("deleteCompany,wrong..................");//这里总是得不到DAO层出现的异常
}}
我做了一个DAO类DAO方法
public void doExec(String sql_IDU) throws SQLException {try
{
.......
} catch (SQLException SQLe) {
status = SQLe.getMessage();
throw new SQLException()
} finally {
}
}业务层调用
public boolean deleteCompany(String companyId) throws SQLException{
try {
......
dao.doExec(sql.toString());
result = true;
} catch (Exception e) {
System.out.println("deleteCompany,wrong..................");//这里总是得不到DAO层出现的异常
}}
tryexcept
如果向上级抛异常,就用raise exception.create就OK了
end;
你的dao层 正确执行了 就不会抛出了 当然也无逻辑层就无法捕获了你修改下你的代码,人为的抛出SQLException试试业务逻辑层应该可以捕获到的。
2:日志
3:接口
4:静态方法
catch (SQLException SQLe) {
status = SQLe.getMessage();
throw new SQLException()
}
就已经自动向上抛 SQLException了