title: Handling bad CSV records in CsvHelper
body: <p>I would like to be able to iterate through all records in a CSV file and add all the good records to one collection and handle all the "bad" ones separately. I don't seem to be able to do this and I think I must be missing something.</p>
  
  <p>If I attempt to catch the BadDataException then subsequent reads will fail meaning I cannot carry on and read the rest of the file -</p>
  
  <pre><code>while (true)
  {
      try
      {
          if (!reader.Read())
              break;
  
          var record = reader.GetRecord&lt;Record&gt;();
          goodList.Add(record);
      }
      catch (BadDataException ex)
      {
          // Exception is caught but I won't be able to read further rows in file
          // (all further reader.Read() result in same exception thrown)
          Console.WriteLine(ex.Message);
      }
  }
  </code></pre>
  
  <p>The other option discussed is setting the BadDataFound callback action to handle it -</p>
  
  <pre><code>reader.Configuration.BadDataFound = x =&gt;
  {
      Console.WriteLine($"Bad data: &lt;{x.RawRecord}&gt;");
  };
  </code></pre>
  
  <p>However although the callback is called the bad record still ends up in my "good list"</p>
  
  <p>Is there some way I can query the reader to see if the record is good before adding it to my list?</p>
  
  <p>For this example my Record definition is -</p>
  
  <pre><code>class Record
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public int Age { get; set; }
  }
  </code></pre>
  
  <p>And the data (first row bad, second row good) -</p>
  
  <pre><code>"Jo"hn","Doe",43
  "Jane","Doe",21
  </code></pre>
  
  <p>Interestingly handling a missing field with MissingFieldException seems to function exactly as I would like - the exception is thrown but subsequent rows are still read ok.</p>