title: Handling non-fatal errors in Java
body: <p>I've written a program to aid the user in configuring 'mechs for a game. I'm dealing with loading the user's saved data. This data can (and some times does) become partially corrupt (either due to bugs on my side or due to changes in the game data/rules from upstream).</p>
  
  <p>I need to be able to handle this corruption and load as much as possible. To be more specific, the contents of the save file are syntactically correct but semantically corrupt. I can safely parse the file and drop whatever entries that are not semantically OK.</p>
  
  <p>Currently my data parser will just show a modal dialog with an appropriate warning message. However displaying the warning is not the job of the parser and I'm looking for a way of passing this information to the caller. </p>
  
  <p>Some code to show approximately what is going on (in reality there is a bit more going on than this, but this highlights the problem):</p>
  
  <pre><code>class Parser{
      public void parse(XMLNode aNode){
          ...
          if(corrupted) {
              JOptionPane.showMessageDialog(null, "Corrupted data found", 
                  "error!", JOptionPane.WARNING_MESSAGE);
              // Keep calm and carry on
          }
      }
  }
  
  class UserData{
      static UserData loadFromFile(File aFile){
          UserData data = new UserData();
          Parser parser = new Parser();
          XMLDoc doc = fromXml(aFile);
          for(XMLNode entry : doc.allEntries()){
              data.append(parser.parse(entry));
          }
          return data;
      }
  }
  </code></pre>
  
  <p>The thing here is that bar an <code>IOException</code> or a syntax error in the XML, <code>loadFromFile</code> will always succeed in loading <em>something</em> and this is the wanted behavior. Somehow I just need to pass the information of what (if anything) went wrong to the caller. I could return a <code>Pair&lt;UserData,String&gt;</code> but this doesn't look very pretty. Throwing an exception will not work in this case obviously. </p>
  
  <p>Does any one have any ideas on how to solve this?</p>