FileHelpers - ErrorMode.IgnoreAndContinue

  • Contact / Feedback
  • Introduction
  • Download
  • Quick Start
  • Must Read
  • Examples
    • QuickStart
      • Read Delimited File
      • Write Delimited File
      • Read Fixed File
      • Write Fixed File
      • Read or Write Record by Record
      • Autoproperties
    • Missing Values
      • Handle Missing Values with Nullable
      • Handle Missing Values With FieldNullValue
    • Attributes
      • FieldTrim
      • FieldOrder
      • FixedLengthRecord FixedMode.AllowLessChars
    • Converters
      • Enum Converter
      • Custom Converter
    • Events And Notification
      • INotifyRead Interface
      • INotifyWrite Interface
      • Before/After Read Event Handling
      • Before/After Write Event Handling
    • ErrorHandling
      • ErrorMode.ThrowException
      • ErrorMode.IgnoreAndContinue
      • ErrorMode SaveAndContinue
    • Advanced
      • Dynamic Engine Options
      • Multiple Delimiters
      • Multi Record Processing
      • Smart Format Detector
    • Sorting
      • Sort Big File with Record Class
      • Sort Big File without Record Class 1
      • Sort Big File without Record Class 2
    • MasterDetail
      • Master Detail Custom Selector
      • Master Detail Common Selector
  • Credits
  • Invite us a beer
  • Contribute
  • Source Code
  • Api Docs (Sandcastle)
  1. Examples
  2. ErrorHandling
  3. ErrorMode.IgnoreAndContinue
Previous: ErrorMode.ThrowException
Next: ErrorMode SaveAndContinue
Click button to edit
ErrorHandling: ErrorMode.IgnoreAndContinue
Read the file dropping bad records

Another option is to ignore the errors and continue. Here is an example:

Input.txt
ALFKI|Alfreds Futterkiste|Maria Anders|SalesRepresentative
ANATR|Ana Trujillo Emparedados y helados|Ana Trujillo|NotInEnum
FRANR|France restauration|Carine Schmitt|MarketingManager
ANTON|Antonio Moreno Taquería|Antonio Moreno|Owner
Customers with Enum.cs
[DelimitedRecord("|")]
public class Customer
{
    public string CustomerID;
    public string CompanyName;
    public string ContactName;
    public CustomerTitle ContactTitle;
}

public enum CustomerTitle
{
    Owner,
    SalesRepresentative,
    MarketingManager
}
RunEngine.cs
var engine = new DelimitedFileEngine<Customer>();

// Switch error mode on
engine.ErrorManager.ErrorMode = ErrorMode.IgnoreAndContinue;

//  This fails with not in enumeration error
var customers = engine.ReadFile("Input.txt");

// This wont display anything, we have dropped it
foreach (var err in engine.ErrorManager.Errors) {
    Console.WriteLine();
    Console.WriteLine("Error on Line number: {0}", err.LineNumber);
    Console.WriteLine("Record causing the problem: {0}", err.RecordString);
    Console.WriteLine("Complete exception information: {0}", err.ExceptionInfo.ToString());
}

// This will display only 3 of the four records
foreach (var cust in customers)
    Console.WriteLine("Customer name {0} is a {1}", cust.ContactName, cust.ContactTitle);
Console
Customer name Maria Anders is a SalesRepresentative
Customer name Carine Schmitt is a MarketingManager
Customer name Antonio Moreno is a Owner
Copyright © 2020 Devoo - Marcos Meli All rights reserved. Template Design by GeeksLabs