抛异常问题
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异常,所以就有问题了