import java.util.ArrayList;
import java.util.List;
public class TestException {
public static void main(String[] args) {
List<Integer> inputList = new ArrayList<>();
inputList.add(1);
inputList.add(2);
inputList.add(3);
inputList.add(4);
inputList.add(5);
inputList.add(6);
inputList.add(7);
TestException testException = new TestException();
List<Integer> list = testException.dosomething(inputList);
for (Integer i : list) {
System.out.println(list.get(i));
}
}
public List<Integer> dosomething (List<Integer> list) {
List<Integer> resultList = new ArrayList<>();
int temp=0; // 最后成功的数
try {
for (int i=0; i<list.size(); i++) {
temp = i;
if (i==5) {
resultList.add(i/0);
}
resultList.add(i);
}
// return resultList;
} catch (Exception e) {
System.out.println("执行第" + temp + "个执行失败");
//return resultList;
}finally {
return resultList;
}
}
}