开发者社区 问答 正文

java怎么在循环时在抛出异常的同时又能跳到循环的下一条

如题:比如

for(int i=0;i<str.length();i++){
if(i==1){
throw new ApiException("dsf");
//continue;
}
}

展开
收起
蛮大人123 2016-03-26 15:18:43 2911 分享 版权
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    你这个设计有问题啊,如果实在非要这样做,你可以这样写

    for(int i =0;i<str.length;i++){
    try{
    if(i==1){
    throw ApiException("ds");
    }
    System.out.println(i);//这里写1往后的逻辑,亲测可用
    }catch(ApiException e){
    
        }finally{
            continue;
        }
    }
    2019-07-17 19:16:19
    赞同 展开评论
问答分类:
问答标签:
问答地址: