Java exception handling

后端 未结 7 1257
無奈伤痛
無奈伤痛 2020-12-02 00:37

How do I use exceptions and exception handling to make my program continue even if an exception occurs while processing certain files in a set of files?

I want my pr

7条回答
  •  独厮守ぢ
    2020-12-02 01:09

    Typically, I would have done this.

    ArrayList allEntries = getAllEntries();
    
    for(Entry eachEntry:allEntries){
      try{
        //do all your processing for eachEntry
      } catch(Exception e{
         ignoredEntries.add(eachEntry);
         //if concerned, you can store even the specific problem.
      } finally{
         //In case of resource release
      }
    }
    
    if(ignoredEntries.size() > 0){
      //Handle this scenario, may be display the error to the user
    }
    

提交回复
热议问题