异常与循环



1
  对系统exception异常,只能在for内部用try语句捕获异常并处理,for可以继续;如果不捕获,则跳出循环,

不可能再继续(也不能在内部抛异常,抛出之后会崩)

2
3  public static void getProfiles(List<ProfileEntity> plist ,String dir) throws ParseExcepti
  on{
4          File dirFile  = new File(dir);
5          if(dirFile.isFile()) dirFile = dirFile.getParentFile();
6          final File[] fList = dirFile.listFiles();
7          boolean errorFlag = false;
8          if(fList != null){
9              for(File f : fList){
10                  if(!f.getName().endsWith(".xml")) continue;
11                  try {
12                      ProfileEntity pe = getProfile(f);
13                      pe.setFileName(f.getName());
14                      plist.add(pe);
15                  } catch (ParseException e) {
16                      Log.e(LOG_TAG, "Error of Parser : "+e.getMessage());
17                      errorFlag = true;
18                      continue;
19                  }
20              }
21          }
22          if(errorFlag) throw new ParseException("");
23      }