0

I need to log the exception message if any conversion exception comes while iterating data of a file and then continue with next data.

For example, if the input file has 10 records and there is exception raised due to 7th record. Then I need to yield return Rows for 1-6 and 8-10, along with logging exception for 7th record.

I am using the following code to yield rows using data of a file:

public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
    using (FileEngine file = FluentFile.For<SomeDataRecordETL>().From(FilePath))
    {   
        foreach (object obj in file)
        {
            yield return Row.FromObject(obj);
        }
    }
}
svick
  • 236,525
  • 50
  • 385
  • 514
Coding man
  • 957
  • 1
  • 18
  • 44
  • The `FileEngine` may expose an OnError method. The current FileHelpers library has 3 error modes: `ThrowException`, `SaveAndContinue`, and `IgnoreAndContinue`. You might be able to use `SaveAndContinue` as part of your solution. – dalenewman Apr 13 '15 at 21:17

1 Answers1

1

If you're talking about exceptions thrown by FromObject(), then you can just use try-catch:

foreach (object obj in file)
{
    try
    {
        yield return Row.FromObject(obj);
    }
    catch (Exception ex) // ideally, this should be some specific exception type
    {
        Log(ex);
    }
}
svick
  • 236,525
  • 50
  • 385
  • 514