先码一个,try catch没有捕获到OutOFBoundsException

来源:互联网 发布:退火算法 matlab 编辑:程序博客网 时间:2024/06/07 16:44
源码:
public Integer findTypeById(String type) throws Exception {    Integer page = null;    System.out.println(type);    NewsTypeExample newsTypeExample = new NewsTypeExample();    NewsTypeExample.Criteria criteria = newsTypeExample.createCriteria();    criteria.andTypeDirEqualTo(type);    List<NewsType> types = newsTypeMapper.selectByExample(newsTypeExample);    try {        page = types.get(0).getTypeId();    } catch (IndexOutOfBoundsException e) {        throw new CustomException("分类不存在。");    }    return page;}
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0at java.util.ArrayList.rangeCheck(ArrayList.java:653)at java.util.ArrayList.get(ArrayList.java:429)at com.amoxu.service.impl.NewsServiceImpl.findTypeById(NewsServiceImpl.java:75)
期望的是交给CustomerException处理,系统交给全局的控制器处理了。
目前还有找到原因。
待续
好吧 修改文件之后要在maven里clean之后再运行
 
原创粉丝点击