java异常问题,求帮助。

tuyry 2014-01-06 04:46:04

public void doExecute(HttpServletRequest request) throws Throwable {
try {
String filePath = request.getParameter("filepath");//文件路径
String contact_way = "测试01";
String management_style = "测试02";
String operator = "测试03";
FileImpUtils imp = new FileImpUtils();
filePath = imp.change(filePath);
imp.readExcel(filePath, 1);//文件路径、忽略行数
List list2 = null;
List list = imp.getData();//获取数据
int rows = imp.getSum();//总记录数
for (int i = 0; i < rows; i++) {
list2 = (List) list.get(i);
String sql = "insert into t_label_info values ('"
+ list2.get(0) + "','" + list2.get(1) + "','"
+ list2.get(2) + "','" + list2.get(3)
+ "',?,?,?,sysdate)";
setSqlString(sql);
setSqlParameter(1, contact_way);
setSqlParameter(2, management_style);
setSqlParameter(3, operator);
boolean flag = updateSql();
System.out.println(flag);
if(!flag){
throw new OurException("自定义异常!");
}
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally{

}


flag返回false,这个怎么不抛出自定义异常?老师抛出updateSql()这个异常。
...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
tuyry 2014-01-07
  • 打赏
  • 举报
回复
引用 2 楼 a_liujian 的回复:
你try catch定义的是捕获所有的异常,自定义异常抛出的异常被捕获到了,此时抛到上层的异常为 catch块里的throw e;
明白了。
a_jian 2014-01-06
  • 打赏
  • 举报
回复
你try catch定义的是捕获所有的异常,自定义异常抛出的异常被捕获到了,此时抛到上层的异常为 catch块里的throw e;
Test_LD 2014-01-06
  • 打赏
  • 举报
回复
因为你这个throw new OurException,你自己已经try catch了并且catch的是Exception

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧