首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

抛错误有关问题

2012-08-01 
抛异常问题Unreachable catch block for SQLException. This exception is never thrown from the try sta

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

热点排行