当前位置: 代码迷 >> Java Web开发 >> 抛错误有关问题
  详细解决方案

抛错误有关问题

热度:9947   发布时间:2013-02-25 21:15:36.0
抛异常问题
Unreachable catch block for SQLException. This exception is never thrown from the try statement body
try {
emp = empdao.findEmployeeByUserName(userName);
} catch (DataException e) {
logger.error("检查用户名出错", e);
throw new DataException(e);
} catch (SQLException e){
logger.error("数据库出错", e);
throw new DataException(e);
}

请问怎么解决??

------解决方案--------------------------------------------------------
} catch (SQLException e) {
logger.error("查询员工信息失败");
throw new DataException(e);
}
你已经把SQLExcpetion异常转化成DataException异常抛出
所以在调用findEmployeeByUserName的时候是不会抛出SQLException异常了
而你在catch里又去捕获SQLException异常,所以就有问题了
  相关解决方案