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()这个异常。
------解决方案--------------------
你try catch定义的是捕获所有的异常,自定义异常抛出的异常被捕获到了,此时抛到上层的异常为
catch块里的throw e;